### Quick Start Terminal Initialization Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/SUMMARY.md Initialize the default terminal, start its event loop, and defer its stopping. This is the basic setup for any Ultraviolet application. ```go t := uv.DefaultTerminal() t.Start() defer t.Stop() for ev := range t.Events() { /* ... */ } ``` -------------------------------- ### Go Get Command Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/00-START-HERE.md Install the latest version of the Ultraviolet library using go get. Ensure you have Go installed and configured. ```bash go get github.com/charmbracelet/ultraviolet@latest ``` -------------------------------- ### Minimal Ultraviolet Example Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/README.md A basic example demonstrating how to initialize a terminal, enter an alternate screen, draw text, and handle key press events to quit. ```go package main import ( "log" uv "github.com/charmbracelet/ultraviolet" "github.com/charmbracelet/ultraviolet/screen" ) func main() { t := uv.DefaultTerminal() scr := t.Screen() scr.EnterAltScreen() if err := t.Start(); err != nil { log.Fatal(err) } defer t.Stop() ctx := screen.NewContext(scr) ctx.DrawString("Press 'q' to quit", 0, 0) scr.Render() scr.Flush() for ev := range t.Events() { switch ev := ev.(type) { case uv.KeyPressEvent: if ev.MatchString("q") { return } } } } ``` -------------------------------- ### Create Default Terminal Source: https://github.com/charmbracelet/ultraviolet/blob/main/TUTORIAL.md Use this to create a default terminal instance. This is the simplest way to get started with Ultraviolet. ```go t := uv.DefaultTerminal() ``` -------------------------------- ### Start Terminal Source: https://github.com/charmbracelet/ultraviolet/blob/main/TUTORIAL.md Start the terminal to enable raw mode, initialize the event loop, and prepare the screen for rendering. Ensure to defer Stop() to clean up. ```go if err := t.Start(); err != nil { log.Fatalf("failed to start terminal: %v", err) } deffer t.Stop() ``` -------------------------------- ### Install Ultraviolet Source: https://github.com/charmbracelet/ultraviolet/blob/main/README.md Use this command to install the latest version of Ultraviolet. ```bash go get github.com/charmbracelet/ultraviolet@latest ``` -------------------------------- ### Start a Terminal Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/INDEX.md Initializes and starts a new terminal session. Ensure to defer stopping the terminal to clean up resources. ```go t := uv.DefaultTerminal() t.Start() defer t.Stop() ``` -------------------------------- ### Handle Window Resize Event Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/events.md Example of how to use the WindowSizeEvent to update the screen dimensions. ```go case ev := ev.(type).(uv.WindowSizeEvent): scr.Resize(ev.Width, ev.Height) ``` -------------------------------- ### Example: Create and Set a Progress Bar Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/cursor-progress.md Demonstrates creating a new progress bar with a default state and 50% value, then setting it on the screen. ```go pb := uv.NewProgressBar(uv.ProgressBarDefault, 50) scr.SetProgressBar(pb) ``` -------------------------------- ### Example Usage of Rect Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/types.md Demonstrates how to create a Rectangle using the Rect function with specified coordinates and dimensions. ```go area := uv.Rect(0, 0, 80, 24) // x=0, y=0, width=80, height=24 ``` -------------------------------- ### Quick Start: Basic TUI Application Source: https://github.com/charmbracelet/ultraviolet/blob/main/README.md A minimal Go program demonstrating how to initialize Ultraviolet, enter an alternate screen, draw text, and handle basic events like window resizing and key presses. ```go package main import ( "log" uv "github.com/charmbracelet/ultraviolet" "github.com/charmbracelet/ultraviolet/screen" ) func main() { t := uv.DefaultTerminal() scr := t.Screen() scr.EnterAltScreen() if err := t.Start(); err != nil { log.Fatalf("failed to start terminal: %v", err) } defer t.Stop() ctx := screen.NewContext(scr) text := "Hello, World!" textWidth := scr.StringWidth(text) display := func() { screen.Clear(scr) bounds := scr.Bounds() x := (bounds.Dx() - textWidth) / 2 y := bounds.Dy() / 2 ctx.DrawString(text, x, y) scr.Render() scr.Flush() } for ev := range t.Events() { switch ev := ev.(type) { case uv.WindowSizeEvent: scr.Resize(ev.Width, ev.Height) display() case uv.KeyPressEvent: if ev.MatchString("q", "ctrl+c") { return } } } } ``` -------------------------------- ### Complete Hello World TUI Source: https://github.com/charmbracelet/ultraviolet/blob/main/TUTORIAL.md A full example of a centered "Hello, World!" TUI that redraws on resize and exits on 'q' or Ctrl+C. ```go package main import ( "log" uv "github.com/charmbracelet/ultraviolet" "github.com/charmbracelet/ultraviolet/screen" ) func main() { t := uv.DefaultTerminal() scr := t.Screen() schr.EnterAltScreen() if err := t.Start(); err != nil { log.Fatalf("failed to start terminal: %v", err) } defer t.Stop() ctx := screen.NewContext(scr) text := "Hello, World!" textWidth := scr.StringWidth(text) display := func() { screen.Clear(scr) bounds := scr.Bounds() x := (bounds.Dx() - textWidth) / 2 y := bounds.Dy() / 2 ctx.DrawString(text, x, y) schr.Render() schr.Flush() } for ev := range t.Events() { switch ev := ev.(type) { case uv.WindowSizeEvent: schr.Resize(ev.Width, ev.Height) display() case uv.KeyPressEvent: if ev.MatchString("q", "ctrl+c") { return } } } } ``` -------------------------------- ### Handle Mouse Click Event Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/events.md Example of how to handle a MouseClickEvent, extracting the click coordinates. ```go case ev := ev.(type).(uv.MouseClickEvent): m := ev.Mouse() fmt.Printf("Clicked at %d,%d\n", m.X, m.Y) ``` -------------------------------- ### Example: Displaying Different Progress Bar States Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/cursor-progress.md Shows how to display a progress bar at 75% completion, an error state, and how to hide the progress bar entirely. ```go // Show 75% progress pb := uv.NewProgressBar(uv.ProgressBarDefault, 75) scr.SetProgressBar(pb) // Show error state errorPb := uv.NewProgressBar(uv.ProgressBarError, 0) scr.SetProgressBar(errorPb) // Hide progress bar scr.SetProgressBar(uv.NewProgressBar(uv.ProgressBarNone, 0)) ``` -------------------------------- ### Setting Underline Style Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/cell.md Example of creating a Style object and setting a specific underline style, such as a double underline. This shows how to apply underline formatting. ```go style := &uv.Style{ Underline: uv.UnlineDouble, } ``` -------------------------------- ### Full-Screen Terminal UI Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/README.md Initialize a terminal, enter an alternate screen, and start the event loop for drawing and handling input. Use defer to ensure the terminal is stopped. ```go t := uv.DefaultTerminal() scr := t.Screen() scr.EnterAltScreen() t.Start() def t.Stop() // Draw loop for { scr.Render() scr.Flush() select { case ev := <-t.Events(): switch ev := ev.(type) { case uv.WindowSizeEvent: scr.Resize(ev.Width, ev.Height) case uv.KeyPressEvent: // Handle input } } } ``` -------------------------------- ### Handle Mouse Wheel Scroll Event Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/events.md Example of how to handle a MouseWheelEvent to detect scrolling up. ```go case ev := ev.(type).(uv.MouseWheelEvent): if ev.Mouse().Button == uv.MouseWheelUp { scrollUp() } ``` -------------------------------- ### Handle Key Press Event Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/events.md Example of processing a KeyPressEvent, including checking for specific key combinations like 'ctrl+c' or 'q'. ```go case ev := ev.(type).(uv.KeyPressEvent): if ev.MatchString("ctrl+c", "q") { return } ``` -------------------------------- ### Applying Text Attributes Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/cell.md Example of combining text attribute constants to create a Style object. This demonstrates how to set multiple text styles simultaneously. ```go attrs := uv.AttrBold | uv.AttrUnderline style := &uv.Style{Attrs: attrs} ``` -------------------------------- ### Start Terminal Event Loop Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal.md Starts the terminal application's event loop. This function is non-blocking; use `Wait()` to block until the loop exits. Ensure to call `Stop()` to clean up resources. ```go if err := t.Start(); err != nil { log.Fatal(err) } defer t.Stop() ``` -------------------------------- ### Terminal.Start Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal.md Starts the terminal application event loop. This method is non-blocking, and `Wait()` should be used to block until the loop exits. ```APIDOC ## Terminal.Start ### Description Starts the terminal application event loop. This is non-blocking; use `Wait()` to wait for the loop to exit. ### Returns * `error` - If the terminal fails to enter raw mode or set up the event loop. ### Example ```go if err := t.Start(); err != nil { log.Fatal(err) } defer t.Stop() ``` ``` -------------------------------- ### Get Window Bounds Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Retrieves the current dimensions and position of the window. ```go func (w *Window) Bounds() Rectangle ``` -------------------------------- ### Calculating String Width Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-helpers.md Example of using the StringWidth method from the WidthMethod interface to determine the number of cells a string will occupy. ```go width := scr.WidthMethod().StringWidth("Hello") // Returns the number of cells needed to display "Hello" ``` -------------------------------- ### Configure Keyboard Enhancements Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/configuration.md Example of setting specific keyboard enhancements like disambiguating escape codes and reporting event types. This configuration might not be supported by all terminals. ```go ke := &uv.KeyboardEnhancements{ DisambiguateEscapeCodes: true, ReportEventTypes: true, } if err := scr.SetKeyboardEnhancements(ke); err != nil { log.Println("Keyboard enhancements not supported") } ``` -------------------------------- ### DefaultTerminal Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal.md Creates a new terminal instance using the default standard console and default options. This is the primary way to get a new terminal. ```APIDOC ## DefaultTerminal ### Description Creates a new terminal instance using the default standard console and default options. ### Returns * `*Terminal` - A new terminal instance using stdin/stdout. ### Example ```go t := uv.DefaultTerminal() scr := t.Screen() ``` ``` -------------------------------- ### Run in Inline Mode Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/usage-patterns.md Use this pattern for status output or interactive CLIs without entering fullscreen mode. Ensure terminal is started and stopped correctly. ```go func main() { t := uv.DefaultTerminal() scr := t.Screen() // Don't enter alt screen - use inline mode // scr.EnterAltScreen() if err := t.Start(); err != nil { log.Fatal(err) } defer t.Stop() fmt.Println("Running in inline mode") ctx := screen.NewContext(scr) ctx.DrawString("Status: Ready", 0, 0) scr.Render() scr.Flush() for ev := range t.Events() { switch ev := ev.(type) { case uv.KeyPressEvent: if ev.MatchString("q") { return } } } } ``` -------------------------------- ### Check for Left Mouse Click Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/key-mouse.md An example demonstrating how to check if the left mouse button was pressed using the MouseLeft constant. ```go if ev.Mouse().Button == uv.MouseLeft { handleLeftClick() } ``` -------------------------------- ### Check for Specific Function Key Press Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/key-mouse.md An example demonstrating how to check if a specific function key, such as F1, has been pressed by comparing its code. ```go if key.Code == uv.KeyF1 { showHelp() } ``` -------------------------------- ### Get Default Terminal Options Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/configuration.md Returns the default configuration settings for a new Terminal. This includes default buffer size, event timeout, and key lookup settings. ```go func DefaultOptions() *Options ``` -------------------------------- ### Get Parent Window Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Retrieves the parent window of the current window. Returns nil if the window is a root window. ```go func (w *Window) Parent() *Window ``` -------------------------------- ### Get Width Method Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal-screen.md Retrieves the current width calculation method used by the terminal screen. This indicates how character widths are determined. ```go method := scr.WidthMethod() ``` -------------------------------- ### Get Window Width Method Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Retrieves the current width calculation method used by the window. This indicates how the window's width is determined. ```go func (w *Window) WidthMethod() WidthMethod ``` -------------------------------- ### Get TerminalScreen Height Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal-screen.md Returns the height of the managed screen in rows. ```go func (s *TerminalScreen) Height() int ``` -------------------------------- ### Options Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/types.md Configuration options for creating a terminal instance. ```APIDOC ## Options ### Description Configuration options for creating a terminal instance. ### Type Definition ```go type Options struct { BufferSize int EventTimeout time.Duration LegacyKeyEncoding LegacyKeyEncoding LookupKeys bool UseTerminfoKeys bool Logger Logger } ``` ### Constructor `DefaultOptions()` ``` -------------------------------- ### Get Current Drawing Position Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Retrieves the current drawing position (x, y coordinates) of the context. ```go func (c *Context) Position() Position ``` -------------------------------- ### Create a New Layout Solver Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/layout.md Use `layout.New` to initialize a layout solver with a set of size constraints. This is useful for defining how screen space should be divided. ```go layout := layout.New( layout.Fill(1), // Top takes remaining space layout.Len(1), // Bottom takes exactly 1 cell ) ``` -------------------------------- ### Get TerminalScreen Width Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal-screen.md Returns the width of the managed screen in columns. This is not the actual terminal width. ```go func (s *TerminalScreen) Width() int ``` -------------------------------- ### Handling Input Events Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/README.md Shows how to receive and process various input events like key presses, mouse clicks, and window resize events. ```go for ev := range t.Events() { switch ev := ev.(type) { case uv.KeyPressEvent: // Handle keyboard case uv.MouseClickEvent: // Handle mouse case uv.WindowSizeEvent: // Handle resize } } ``` -------------------------------- ### Get Cell String Content Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/cell.md Retrieves the string content of a cell, excluding any styling information. ```go content := cell.String() ``` -------------------------------- ### Get Buffer Height Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Returns the height of the buffer in rows. This indicates the number of rows available for rendering. ```go func (b *Buffer) Height() int ``` -------------------------------- ### Import Main Ultraviolet Package Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/INDEX.md Import the main Ultraviolet package. You can use the standard import path or an alias. ```go import "github.com/charmbracelet/ultraviolet" // or import uv "github.com/charmbracelet/ultraviolet" ``` -------------------------------- ### Get Buffer Width Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Returns the width of the buffer in columns. This indicates the number of columns available for rendering. ```go func (b *Buffer) Width() int ``` -------------------------------- ### Get Buffer Bounds Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Returns the bounds of the buffer as a Rectangle. This is useful for understanding the dimensions of the rendering area. ```go func (b *Buffer) Bounds() Rectangle ``` ```go bounds := buf.Bounds() ``` -------------------------------- ### Rendering Widget with Screen Interface Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-helpers.md Demonstrates how to write rendering code against the Screen interface to ensure compatibility with different screen implementations like TerminalScreen, Buffer, and Window. ```go func renderWidget(scr uv.Screen) { bounds := scr.Bounds() cell := &uv.Cell{Content: "X", Width: 1} scr.SetCell(bounds.Min.X, bounds.Min.Y, cell) } // Works with any Screen implementation renderWidget(terminalScreen) renderWidget(buffer) renderWidget(window) ``` -------------------------------- ### Create New Root Window Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Creates a new root window with specified dimensions and width calculation method. The method parameter defaults to WcWidth if nil. ```go func NewWindow(width, height int, method WidthMethod) *Window ``` ```go win := uv.NewWindow(80, 24, ansi.WcWidth) ``` -------------------------------- ### Get TerminalScreen Bounds Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal-screen.md Retrieves the dimensions of the terminal screen. This is useful for determining the available drawing area. ```go func (s *TerminalScreen) Bounds() Rectangle ``` ```go bounds := scr.Bounds() width := bounds.Max.X - bounds.Min.X height := bounds.Max.Y - bounds.Min.Y ``` -------------------------------- ### Import Ultraviolet Layout Package Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/INDEX.md Import the layout package from Ultraviolet for layout management functionalities. ```go import "github.com/charmbracelet/ultraviolet/layout" ``` -------------------------------- ### Create Custom Terminal Instance Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal.md Creates a new terminal instance with a specific console and options. Both parameters can be nil to use defaults, allowing for flexible terminal configuration. ```go console := uv.DefaultConsole() opts := uv.DefaultOptions() t := uv.NewTerminal(console, opts) ``` -------------------------------- ### Get Terminal Screen Source: https://github.com/charmbracelet/ultraviolet/blob/main/TUTORIAL.md Retrieve the screen object associated with the terminal. The screen is used for drawing and managing the display. ```go scr := t.Screen() ``` -------------------------------- ### Drawing with Screen Context Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/README.md Demonstrates how to set foreground color and bold text using the screen context for drawing. ```go ctx := screen.NewContext(scr) ctx.SetForeground(color.White) ctx.SetBold(true) ctx.DrawString("Bold white text", 0, 0) ``` -------------------------------- ### Check for ErrNotTerminal Error Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/errors.md Example of how to check if an error returned from a terminal operation is ErrNotTerminal, indicating the program is not running in a terminal. ```go if err := t.Start(); err != nil { if err == uv.ErrNotTerminal { fmt.Println("Not running in a terminal") } } ``` -------------------------------- ### Configure Cursor Options Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/configuration.md Create a cursor with specific position, shape, blink, and color properties. Use this when you need to customize the cursor's appearance and behavior. ```go cursor := &uv.Cursor{ Position: uv.Pos(10, 5), Shape: uv.CursorBlock, Blink: true, Hidden: false, Color: nil, // Use default } if err := scr.SetCursor(cursor); err != nil { log.Println("Could not set cursor") } ``` -------------------------------- ### Render to Screen Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/INDEX.md Creates a screen context, draws content, and then renders and flushes the screen. This is used to display UI elements. ```go ctx := screen.NewContext(scr) ctx.DrawString("Hello", 0, 0) scr.Render() scr.Flush() ``` -------------------------------- ### Create Custom Terminal Source: https://github.com/charmbracelet/ultraviolet/blob/main/TUTORIAL.md Create a terminal with a custom console and options. Useful for advanced configurations or testing. ```go con := uv.NewConsole(os.Stdin, os.Stdout, os.Environ()) t := uv.NewTerminal(con, &uv.Options{ Logger: myLogger, // optional, for debugging I/O }) ``` -------------------------------- ### Define Environ Interface Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/types.md An interface for accessing environment variables. It defines a single method to get the value of an environment variable by its key. ```go type Environ interface { Getenv(key string) string } ``` -------------------------------- ### Create New TerminalScreen Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal-screen.md Initializes a new TerminalScreen instance. Use this to manage terminal output and environment configurations. ```go func NewTerminalScreen(w io.Writer, env Environ) *TerminalScreen ``` ```go scr := uv.NewTerminalScreen(os.Stdout, os.Environ) ``` -------------------------------- ### Get Cell at Coordinates Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal-screen.md Fetches the specific cell at a given X and Y coordinate on the terminal screen. Returns nil if the coordinates are out of bounds. ```go func (s *TerminalScreen) CellAt(x, y int) *Cell ``` ```go cell := scr.CellAt(0, 0) ``` -------------------------------- ### NewWindow (Root) Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Creates a new root window with the specified dimensions and character width calculation method. This is the entry point for creating top-level windows. ```APIDOC ## NewWindow ### Description Creates a new root window with the specified size and width calculation method. ### Method func NewWindow(width, height int, method WidthMethod) *Window ### Parameters #### Path Parameters - **width** (int) - Required - Width in columns - **height** (int) - Required - Height in rows - **method** (WidthMethod) - Optional - Character width calculation method (nil defaults to WcWidth) ### Returns - ***Window** — A new root window. ### Example ```go win := uv.NewWindow(80, 24, ansi.WcWidth) ``` ``` -------------------------------- ### Get Terminal Size (Characters) Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal.md Retrieves the current width and height of the terminal in characters. Handles potential errors during the retrieval process. ```go func (t *Terminal) GetSize() (width, height int, err error) ``` ```go w, h, err := t.GetSize() if err != nil { log.Fatal(err) } fmt.Printf("Terminal size: %dx%d\n", w, h) ``` -------------------------------- ### Create Default Terminal Instance Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal.md Creates a new terminal instance using the default standard console and options. This is useful for basic terminal interactions. ```go t := uv.DefaultTerminal() scr := t.Screen() ``` -------------------------------- ### Import Ultraviolet Screen Package Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/INDEX.md Import the screen package from Ultraviolet for screen-related functionalities. ```go import "github.com/charmbracelet/ultraviolet/screen" ``` -------------------------------- ### Clone Screen to Buffer Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-helpers.md Creates a copy of the entire screen into a new buffer. Use this to back up the current screen state. ```go func Clone(scr Screen) *Buffer ``` ```go backup := screen.Clone(scr) // Later: restore backup.Draw(scr, scr.Bounds()) ``` -------------------------------- ### BackgroundColorEvent Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/events.md Represents the background color, typically in response to a color request. It provides methods to get the hex representation and check if the color is dark. ```APIDOC ## BackgroundColorEvent ### Description Sent in response to a background color request. ### Methods - **String()** - Returns hex representation of the color. - **IsDark()** - Returns whether the color is dark. ``` -------------------------------- ### Create New KeyboardEnhancements Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/cursor-progress.md Creates a new KeyboardEnhancements configuration from Kitty keyboard protocol flags. Use 0 or a negative value for no enhancements. ```go func NewKeyboardEnhancements(flags int) *KeyboardEnhancements ``` -------------------------------- ### New Layout Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/layout.md Creates a new layout solver with the specified size constraints. The solver will use these constraints to partition screen space. ```APIDOC ## New Creates a new layout with the given constraints. ### Function Signature ```go func New(constraints ...Constraint) *Layout ``` ### Parameters - **constraints** (...Constraint) - Description: Size constraints for segments ### Returns - **`*Layout`** - A new layout solver. ### Example ```go layout := layout.New( layout.Fill(1), // Top takes remaining space layout.Len(1), // Bottom takes exactly 1 cell ) ``` ``` -------------------------------- ### ForegroundColorEvent Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/events.md Represents the foreground color, typically in response to a color request. It provides methods to get the hex representation and check if the color is dark. ```APIDOC ## ForegroundColorEvent ### Description Sent in response to a foreground color request. ### Methods - **String()** - Returns hex representation of the color. - **IsDark()** - Returns whether the color is dark. ``` -------------------------------- ### Clone Window Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Creates an exact copy of the window including its buffer. Use this when you need a duplicate of the current window state. ```go func (w *Window) Clone() *Window ``` -------------------------------- ### Create Screen Context Copy with Style Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Returns a copy of the context with a new style applied, leaving the original context unchanged. Use this for temporary style modifications. ```go func (c Context) WithStyle(style Style) Context { return Context{} } ``` ```go newCtx := ctx.WithStyle(boldStyle) ``` -------------------------------- ### Check for ErrPlatformNotSupported Error Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/errors.md Example of how to check if an error returned from a terminal operation is ErrPlatformNotSupported, indicating terminal features are unavailable on the current platform. ```go if err := t.Start(); err != nil { if err == uv.ErrPlatformNotSupported { fmt.Println("Terminal features not available on this platform") } } ``` -------------------------------- ### Off-Screen Rendering to Buffer Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/README.md Create an off-screen buffer, draw content to it using a context, and then copy the buffer's content to the main screen. ```go // Create buffer buf := uv.NewBuffer(80, 24) ctx := screen.NewContext(buf) // Draw to buffer ctx.DrawString("Buffered content", 0, 0) // Copy to screen buf.Draw(scr, scr.Bounds()) scr.Render() scr.Flush() ``` -------------------------------- ### Screen Interface Definition Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-helpers.md Defines the contract for screen objects, including methods to get bounds, access and modify cells, and determine the width method. ```go type Screen interface { // Bounds returns the bounds of the screen Bounds() Rectangle // CellAt returns the cell at the given position CellAt(x, y int) *Cell // SetCell sets the cell at the given position SetCell(x, y int, c *Cell) // WidthMethod returns the width method used WidthMethod() WidthMethod } ``` -------------------------------- ### Basic Event Loop Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/usage-patterns.md The simplest pattern for handling terminal events. This snippet demonstrates how to initialize a terminal, enter fullscreen mode, and process basic events like window resizing and key presses. ```go package main import ( "log" uv "github.com/charmbracelet/ultraviolet" "github.com/charmbracelet/ultraviolet/screen" ) func main() { t := uv.DefaultTerminal() scr := t.Screen() // Enter fullscreen mode scr.EnterAltScreen() // Start event loop if err := t.Start(); err != nil { log.Fatal(err) } defer t.Stop() // Main loop for ev := range t.Events() { switch ev := ev.(type) { case uv.WindowSizeEvent: scr.Resize(ev.Width, ev.Height) render(scr) case uv.KeyPressEvent: if ev.MatchString("q", "ctrl+c") { return } } } } func render(scr *uv.TerminalScreen) { screen.Clear(scr) ctx := screen.NewContext(scr) ctx.DrawString("Hello, World!", 0, 0) scr.Render() scr.Flush() } ``` -------------------------------- ### Get Keyboard Enhancement Flags Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/cursor-progress.md Retrieves the keyboard enhancement settings as a bitmask of Kitty keyboard protocol flags. This is useful for configuring terminal behavior. ```go ke := &uv.KeyboardEnhancements{ DisambiguateEscapeCodes: true, ReportEventTypes: true, } flags := ke.Flags() ``` -------------------------------- ### Handle PasteEvent in Go Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/events.md Example of how to handle a PasteEvent in Go, appending the pasted content to a buffer. This is used when text is pasted (bracketed paste mode). ```go case ev := ev.(type).(uv.PasteEvent): buffer.WriteString(ev.Content) ``` -------------------------------- ### Create Multi-Pane Layouts Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/usage-patterns.md Utilize the layout system to divide the screen into multiple panes for complex arrangements like headers, footers, sidebars, and content areas. This enables structured screen design. ```go func layoutScreen(scr uv.Screen) { bounds := scr.Bounds() // Split into header, body, footer headerFooterLayout := layout.New( layout.Len(1), // Header: 1 row layout.Fill(1), // Body: remaining layout.Len(1), // Footer: 1 row ) areas := headerFooterLayout.Split(bounds) headerArea := areas[0] bodyArea := areas[1] footerArea := areas[2] // Split body into sidebar and content sidebarContentLayout := layout.New( layout.Len(20), // Sidebar: 20 columns layout.Fill(1), // Content: remaining ) bodyAreas := sidebarContentLayout.Split(bodyArea) sidebarArea := bodyAreas[0] contentArea := bodyAreas[1] // Draw each pane drawHeader(scr, headerArea) drawSidebar(scr, sidebarArea) drawContent(scr, contentArea) drawFooter(scr, footerArea) } ``` -------------------------------- ### Set Window Width Method Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Configures the width calculation method for the window. Choose the appropriate method based on your layout needs. ```go func (w *Window) SetWidthMethod(method WidthMethod) ``` -------------------------------- ### Create New Screen Context Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Creates a new drawing context for a given screen with default settings. Use this to initialize drawing operations. ```go func NewContext(scr Screen) *Context { return &Context{} } ``` ```go ctx := screen.NewContext(scr) ctx.SetForeground(color.White) ctx.DrawString("Hello", 0, 0) ``` -------------------------------- ### Constraint-Based Layout Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/README.md Define a layout using constraints like Len, Fill, and Ratio, then split the screen bounds according to these constraints. ```go layout := layout.New( layout.Len(3), // Header: 3 rows layout.Fill(1), // Content: remaining layout.Len(1), // Footer: 1 row ) rects := layout.Split(scr.Bounds()) // rects[0] = header area // rects[1] = content area // rects[2] = footer area ``` -------------------------------- ### Create a Three-Pane Layout Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/layout.md Create a three-pane layout by splitting the screen area into a header, sidebar, and the remaining content area. Nested layouts can be used for further partitioning. ```go area := scr.Bounds() rects := layout.New( layout.Len(2), // Header (2 rows) layout.Ratio(1, 4), // Sidebar (1/4 width) ).Split(area) headerArea := rects[0] sidebarArea := rects[1] // Now split the remaining space horizontally rightArea := area rightArea.Min.X = sidebarArea.Max.X // You can nest layouts for complex partitioning ``` -------------------------------- ### Stop Terminal Event Loop Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal.md Stops the terminal event loop. This function is safe to call multiple times. After Stop returns, Start may be called again. ```go func (t *Terminal) Stop() error defer t.Stop() ``` -------------------------------- ### DefaultOptions Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal.md Returns the default terminal options for creating a new Terminal instance. ```APIDOC ## DefaultOptions ### Description Returns the default terminal options. ### Method ```go func DefaultOptions() *Options ``` ### Returns * **Options** - Default configuration. ``` -------------------------------- ### Create New Buffer Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Creates a new buffer with the specified width and height. Use this to initialize an off-screen rendering area. ```go func NewBuffer(width, height int) *Buffer ``` ```go buf := uv.NewBuffer(80, 24) ``` -------------------------------- ### Key.String Method Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/key-mouse.md Returns a human-readable string representation of a key press, including modifiers. ```go func (k Key) String() string ``` ```go fmt.Println(key.String()) // "ctrl+shift+a" ``` -------------------------------- ### Get String Width Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal-screen.md Returns the cell width of a string using the terminal's configured width method. Use this to accurately measure text length in cells. ```go w := scr.StringWidth("Hello") ``` -------------------------------- ### Create Context with Strikethrough Style Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Returns a copy of the context with strikethrough enabled or disabled. The original context remains unchanged. ```go func (c Context) WithStrikethrough(strikethrough bool) Context ``` -------------------------------- ### Project Output Structure Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/SUMMARY.md This snippet details the directory structure of the generated documentation for the Ultraviolet library. It includes the master index, overview, type definitions, configuration, error handling, usage patterns, and detailed API reference modules. ```markdown /workspace/home/output/ ├── INDEX.md (Master index and quick reference) ├── README.md (Overview and getting started) ├── types.md (Complete type definitions) ├── configuration.md (Setup and configuration) ├── errors.md (Error handling reference) ├── usage-patterns.md (Common patterns and examples) └── api-reference/ (Detailed API documentation) ├── terminal.md (Terminal lifecycle) ├── terminal-screen.md (Screen rendering) ├── screen-context.md (Drawing context) ├── buffer-window.md (Buffers and windows) ├── cell.md (Cells and styling) ├── events.md (Event types) ├── key-mouse.md (Input handling) ├── cursor-progress.md (Cursor and progress) ├── screen-helpers.md (Utility functions) └── layout.md (Layout system) ``` -------------------------------- ### screen.Clone Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-helpers.md Creates a copy of the entire screen as a buffer. This is useful for backing up the current screen state. ```APIDOC ## screen.Clone ### Description Creates a copy of the entire screen as a buffer. ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Method N/A (Function Call) ### Endpoint N/A (Function Call) ### Returns - `*Buffer` — A new buffer with the screen's contents. ### Example ```go backup := screen.Clone(scr) // Later: restore backup.Draw(scr, scr.Bounds()) ``` ``` -------------------------------- ### Get ANSI SGR Escape Sequence for Style Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/cell.md Use this method to retrieve the ANSI SGR escape sequence for a given style. This is useful for manually constructing styled strings. ```go func (s *Style) String() string ``` ```go seq := style.String() fmt.Print(seq + "Hello" + ansi.ResetStyle) ``` -------------------------------- ### Get Terminal Size (Characters and Pixels) Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal.md Retrieves detailed terminal size information, including character and pixel dimensions. Returns a Winsize struct or an error if the size cannot be obtained. ```go func (t *Terminal) GetWinsize() (*Winsize, error) ``` ```go ws, err := t.GetWinsize() if err != nil { log.Fatal(err) } ``` -------------------------------- ### Copy with Background Color Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Returns a copy of the context with a specified background color. ```go newCtx := ctx.WithBackground(color.Black) ``` -------------------------------- ### Input Creation Functions Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/INDEX.md Functions for initializing input-related components like cursors and progress bars. ```APIDOC ## Input Creation ### `NewCursor()` Creates a new cursor. ### `NewProgressBar()` Creates a new progress bar. ### `NewKeyboardEnhancements()` Creates a new keyboard enhancements configuration. ``` -------------------------------- ### Graceful Fallback on Error Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/errors.md Implement graceful fallbacks when a specific feature or mode is not supported. This example shows falling back to click mode if mouse drag mode fails. ```go if err := scr.SetMouseMode(uv.MouseModeDrag); err != nil { log.Println("Mouse drag not supported, using click mode") scr.SetMouseMode(uv.MouseModeClick) } ``` -------------------------------- ### Draw Text Within Screen Bounds Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/usage-patterns.md Safely draws text on a screen only if the starting position is within the screen's boundaries. It calculates the available width to prevent drawing outside the screen. ```go func drawInBounds(scr uv.Screen, x, y int, text string) int { bounds := scr.Bounds() // Check if position is within bounds if x < bounds.Min.X || y < bounds.Min.Y || x >= bounds.Max.X || y >= bounds.Max.Y { return 0 } // Calculate available width availableWidth := bounds.Max.X - x if availableWidth <= 0 { return 0 } ctx := screen.NewContext(scr) return ctx.DrawString(text, x, y) } ``` -------------------------------- ### Terminal Creation Functions Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/INDEX.md Functions for creating and initializing terminal instances with default or custom options. ```APIDOC ## Terminal Creation ### `DefaultTerminal()` Creates a new terminal instance with default options. ### `NewTerminal()` Creates a new terminal instance. ### `ControllingTerminal()` Returns the controlling terminal and any associated error. ### `DefaultOptions()` Returns a new terminal options struct with default values. ``` -------------------------------- ### Screen Interface Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-helpers.md The Screen interface provides methods to get the screen bounds, retrieve or set a cell at a specific position, and determine the width calculation method used. It is implemented by TerminalScreen, Buffer, and Window. ```APIDOC ## Screen Interface ### Description Represents an interface for rendering content on a screen, providing access to its dimensions and individual cells. ### Methods - **Bounds() Rectangle**: Returns the bounding box of the screen. - **CellAt(x, y int) *Cell**: Retrieves the cell at the specified coordinates (x, y). - **SetCell(x, y int, c *Cell)**: Sets the cell at the specified coordinates (x, y) to the provided cell object. - **WidthMethod() WidthMethod**: Returns the WidthMethod implementation used for calculating string display widths. ``` -------------------------------- ### Draw String with Screen Context Source: https://github.com/charmbracelet/ultraviolet/blob/main/TUTORIAL.md Use the screen context helper to draw strings conveniently. It supports styled text, links, and wrapping, and implements io.Writer. ```go ctx := screen.NewContext(scr) ctx.DrawString("Hello, World!", 0, 0) ``` -------------------------------- ### Configure Progress Bar States Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/configuration.md Create and set progress bar states including default, error, indeterminate, and none. Use this to visually represent task progress or status. ```go // Show 75% progress pb := uv.NewProgressBar(uv.ProgressBarDefault, 75) if err := scr.SetProgressBar(pb); err != nil { log.Println("Progress bar not supported") } // Error state errorPb := uv.NewProgressBar(uv.ProgressBarError, 0) // Indeterminate (usually shows animation) indeterminatePb := uv.NewProgressBar(uv.ProgressBarIndeterminate, 0) // Hide progress bar scr.SetProgressBar(uv.NewProgressBar(uv.ProgressBarNone, 0)) ``` -------------------------------- ### Copy with Bold Setting Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Returns a copy of the context with bold enabled or disabled. ```go newCtx := ctx.WithBold(true) ``` -------------------------------- ### NewKeyboardEnhancements Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/cursor-progress.md Creates keyboard enhancements from Kitty keyboard protocol flags. ```APIDOC ## NewKeyboardEnhancements ### Description Creates keyboard enhancements from Kitty keyboard protocol flags. ### Parameters #### Path Parameters * **flags** (`int`) - Kitty keyboard flags (0 or negative = no enhancements) ### Returns - `*KeyboardEnhancements` — New enhancements configuration. ``` -------------------------------- ### NewTerminal Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal.md Creates a new terminal instance with the given console and options. Both parameters can be nil to use defaults, providing flexibility in terminal configuration. ```APIDOC ## NewTerminal ### Description Creates a new terminal instance with the given console and options. Both parameters can be nil to use defaults. ### Parameters #### Parameters * **con** (`Console`) - Optional - Console for terminal I/O. Defaults to nil. * **opts** (`*Options`) - Optional - Configuration options. Defaults to nil. ### Returns * `*Terminal` - A new terminal instance. ### Example ```go console := uv.DefaultConsole() opts := uv.DefaultOptions() t := uv.NewTerminal(console, opts) ``` ``` -------------------------------- ### Create New Window View Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Creates a new view that shares the parent's buffer. Use when a sub-window needs to display content from the same buffer as its parent. ```go func (w *Window) NewView(x, y, width, height int) *Window view := parent.NewView(0, 0, 40, 20) ``` -------------------------------- ### Render and Flush Screen Source: https://github.com/charmbracelet/ultraviolet/blob/main/TUTORIAL.md Render computes the screen diff and Flush writes it to the terminal. Flush performs the actual I/O and can return an error. ```go scr.Render() if err := scr.Flush(); err != nil { log.Fatalf("flush failed: %v", err) } ``` -------------------------------- ### Set Bold Text Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Sets whether the text should be rendered in bold. ```go ctx.SetBold(true) ``` -------------------------------- ### NewCursor Function Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/cursor-progress.md Creates a new cursor instance at a specified position with default settings. Use this to initialize a cursor before configuring its appearance. ```go func NewCursor(x, y int) *Cursor ``` ```go cursor := uv.NewCursor(0, 0) scr.SetCursor(cursor) ``` -------------------------------- ### Context.WithStyle Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Returns a copy of the current context with a new style applied. This allows for temporary styling without modifying the original context. ```APIDOC ## Context.WithStyle ### Description Returns a copy of the context with the given style applied. ### Parameters #### Path Parameters - **style** (Style) - Required - The style to apply ### Returns - **`Context`** - A new context copy. ### Example ```go newCtx := ctx.WithStyle(boldStyle) ``` ``` -------------------------------- ### Draw Text with Colors Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/usage-patterns.md Use this pattern to draw text in different colors using RGBA values. Requires importing the `image/color` package. ```go import "image/color" func drawColoredText(scr uv.Screen) { ctx := screen.NewContext(scr) // RGBA colors red := color.RGBA{R: 255, G: 0, B: 0, A: 255} green := color.RGBA{R: 0, G: 255, B: 0, A: 255} blue := color.RGBA{R: 0, G: 0, B: 255, A: 255} ctx.SetForeground(red) ctx.DrawString("Red text", 0, 0) ctx.SetForeground(green) ctx.DrawString("Green text", 0, 1) ctx.SetForeground(blue) ctx.DrawString("Blue text", 0, 2) } ``` -------------------------------- ### Create Layout Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/INDEX.md Defines and splits an area into multiple rectangular regions for UI layout. Useful for organizing screen elements. ```go rects := layout.New( layout.Len(5), layout.Fill(1), ).Split(area) ``` -------------------------------- ### Type-Safe Event Handling in Go Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/README.md Demonstrates how to use Go's type assertion to handle different event types, such as key presses and window size changes, ensuring type safety. ```go // Type-safe event handling switch ev := ev.(type) { case uv.KeyPressEvent: // Key is a strongly-typed struct if ev.MatchString("ctrl+c") { /* ... */ } case uv.WindowSizeEvent: // Direct field access fmt.Println(ev.Width, ev.Height) } ``` -------------------------------- ### Terminal Lifecycle Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/README.md Illustrates the typical lifecycle of a terminal application using Ultraviolet. ```text DefaultTerminal() → Terminal.Start() → Terminal.Events() → Terminal.Stop() ``` -------------------------------- ### Set Background Color Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Sets the background color for the context. Use nil to reset to default. ```go ctx.SetBackground(color.Black) ``` -------------------------------- ### NewTerminalScreen Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/terminal-screen.md Creates a new terminal screen instance. It requires an io.Writer for output and an Environ for configuration. ```APIDOC ## NewTerminalScreen ### Description Creates a new terminal screen with the given writer and environment. ### Method func ### Parameters #### Path Parameters - **w** (io.Writer) - Required - Output writer, usually os.Stdout - **env** (Environ) - Required - Environment for configuration ### Response #### Success Response - **TerminalScreen** (*TerminalScreen) - A new screen instance. ### Request Example ```go scr := uv.NewTerminalScreen(os.Stdout, os.Environ) ``` ``` -------------------------------- ### Window.Clone Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Creates an exact copy of the window, including its buffer. This is useful for duplicating window states without affecting the original. ```APIDOC ## Window.Clone ### Description Creates an exact copy of the window including its buffer. ### Returns * `*Window` — A cloned window. ``` -------------------------------- ### Enter Alternate Screen Mode Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/configuration.md Switches the terminal from inline mode to fullscreen mode. Preserves scrollback in inline mode. Use defer to ensure exiting alternate screen mode. ```go if err := scr.EnterAltScreen(); err != nil { log.Fatal(err) } defscr.ExitAltScreen() ``` -------------------------------- ### NewBuffer Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Creates a new buffer with the specified width and height. This is the primary way to initialize a buffer for off-screen rendering. ```APIDOC ## NewBuffer ### Description Creates a new buffer with the specified width and height. ### Method func NewBuffer(width, height int) *Buffer ### Parameters #### Path Parameters - **width** (int) - Required - Width in columns - **height** (int) - Required - Height in rows ### Response #### Success Response (200) - **Returns**: `*Buffer` — A new buffer initialized with empty cells. ### Request Example ```go buf := uv.NewBuffer(80, 24) ``` ``` -------------------------------- ### Create Context with Faint Style Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Returns a new context with the faint text style applied or removed. This is a functional approach, preserving the original context. ```go func (c Context) WithFaint(faint bool) Context ``` -------------------------------- ### Create Rectangle Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/types.md Provides a shorthand function for creating a Rectangle from x, y, width, and height parameters. ```go func Rect(x, y, w, h int) Rectangle ``` -------------------------------- ### Create New Child Window Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Creates a new child window relative to its parent window. The child window will have its own buffer. ```go func (w *Window) NewWindow(x, y, width, height int) *Window ``` ```go child := parent.NewWindow(10, 5, 40, 15) ``` -------------------------------- ### Set Terminal Screen Width Method Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/configuration.md Configures how character widths are calculated for the TerminalScreen. The default method uses wcwidth, while an alternative uses grapheme clusters. ```go scr.SetWidthMethod(ansi.WcWidth) // wcwidth-based (default) scr.SetWidthMethod(ansi.GraphemeWidth) // Grapheme cluster-based ``` -------------------------------- ### Fill Screen with Cell Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-helpers.md Fills the entire screen with a specified cell. Pass `nil` to fill with empty cells. ```go // Fill with empty cells screen.Fill(scr, nil) // Fill with a specific cell cell := &uv.Cell{Content: ".", Width: 1} screen.Fill(scr, cell) ``` -------------------------------- ### Create Context with Blink Style Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/screen-context.md Returns a copy of the context with the blink attribute enabled or disabled. The original context is not affected. ```go func (c Context) WithBlink(blink bool) Context ``` -------------------------------- ### Draw Window to Screen Source: https://github.com/charmbracelet/ultraviolet/blob/main/_autodocs/api-reference/buffer-window.md Renders the window's content onto a target screen within a specified area. This is essential for displaying the window's buffer. ```go func (w *Window) Draw(s Screen, area Rectangle) ```