From 55c7cf2383857599e5cad53f74f811dcf8e4dcde Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sun, 30 Jun 2024 20:09:37 +0200 Subject: [PATCH] refactor: rename ansi to terminal --- src/cli/config_export_image.go | 4 +- src/cli/debug.go | 4 +- src/cli/get.go | 4 +- src/cli/init.go | 4 +- src/engine/block.go | 58 +++++++++---------- src/engine/config.go | 56 +++++++++--------- src/engine/config_test.go | 22 +++---- src/engine/engine.go | 8 +-- src/engine/engine_test.go | 18 +++--- src/engine/image.go | 6 +- src/engine/image_test.go | 4 +- src/engine/new.go | 4 +- src/engine/prompt.go | 4 +- src/engine/segment.go | 8 +-- src/properties/map.go | 4 +- src/{ansi => terminal}/ansi_writer.go | 2 +- .../ansi_writer_hyperlink_test.go | 2 +- src/{ansi => terminal}/ansi_writer_test.go | 2 +- src/{ansi => terminal}/colors.go | 2 +- src/{ansi => terminal}/colors_test.go | 2 +- src/{ansi => terminal}/colors_unix.go | 2 +- src/{ansi => terminal}/colors_windows.go | 2 +- src/{ansi => terminal}/cycle.go | 2 +- src/{ansi => terminal}/iterm.go | 2 +- src/{ansi => terminal}/palette.go | 2 +- src/{ansi => terminal}/palette_test.go | 2 +- src/{ansi => terminal}/palettes.go | 2 +- 27 files changed, 116 insertions(+), 116 deletions(-) rename src/{ansi => terminal}/ansi_writer.go (99%) rename src/{ansi => terminal}/ansi_writer_hyperlink_test.go (99%) rename src/{ansi => terminal}/ansi_writer_test.go (99%) rename src/{ansi => terminal}/colors.go (99%) rename src/{ansi => terminal}/colors_test.go (99%) rename src/{ansi => terminal}/colors_unix.go (96%) rename src/{ansi => terminal}/colors_windows.go (98%) rename src/{ansi => terminal}/cycle.go (88%) rename src/{ansi => terminal}/iterm.go (98%) rename src/{ansi => terminal}/palette.go (99%) rename src/{ansi => terminal}/palette_test.go (99%) rename src/{ansi => terminal}/palettes.go (91%) diff --git a/src/cli/config_export_image.go b/src/cli/config_export_image.go index 9e5becbd..0508e6ce 100644 --- a/src/cli/config_export_image.go +++ b/src/cli/config_export_image.go @@ -3,7 +3,7 @@ package cli import ( "fmt" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/engine" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/shell" @@ -68,7 +68,7 @@ Exports the config to an image file using customized output options.`, env.Var = cfg.Var writerColors := cfg.MakeColors() - writer := &ansi.Writer{ + writer := &terminal.Writer{ TerminalBackground: shell.ConsoleBackgroundColor(env, cfg.TerminalBackground), AnsiColors: writerColors, TrueColor: env.CmdFlags.TrueColor, diff --git a/src/cli/debug.go b/src/cli/debug.go index 475e2f4a..765abc1b 100644 --- a/src/cli/debug.go +++ b/src/cli/debug.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/build" "github.com/jandedobbeleer/oh-my-posh/src/engine" "github.com/jandedobbeleer/oh-my-posh/src/platform" @@ -41,7 +41,7 @@ var debugCmd = &cobra.Command{ env.Var = cfg.Var writerColors := cfg.MakeColors() - writer := &ansi.Writer{ + writer := &terminal.Writer{ TerminalBackground: shell.ConsoleBackgroundColor(env, cfg.TerminalBackground), AnsiColors: writerColors, Plain: plain, diff --git a/src/cli/get.go b/src/cli/get.go index 04ab9893..de073dec 100644 --- a/src/cli/get.go +++ b/src/cli/get.go @@ -5,7 +5,7 @@ import ( "strings" "time" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/platform" color2 "github.com/gookit/color" @@ -56,7 +56,7 @@ This command is used to get the value of the following variables: case "shell": fmt.Println(env.Shell()) case "accent": - rgb, err := ansi.GetAccentColor(env) + rgb, err := terminal.GetAccentColor(env) if err != nil { fmt.Println("error getting accent color:", err.Error()) return diff --git a/src/cli/init.go b/src/cli/init.go index 0caa9819..4f82296e 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -3,10 +3,10 @@ package cli import ( "fmt" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/engine" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/shell" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/jandedobbeleer/oh-my-posh/src/upgrade" "github.com/spf13/cobra" @@ -72,7 +72,7 @@ func runInit(shellName string) { shell.ErrorLine = cfg.ErrorLine != nil || cfg.ValidLine != nil shell.Tooltips = len(cfg.Tooltips) > 0 shell.ShellIntegration = cfg.ShellIntegration - shell.PromptMark = shellName == shell.FISH && cfg.ITermFeatures != nil && cfg.ITermFeatures.Contains(ansi.PromptMark) + shell.PromptMark = shellName == shell.FISH && cfg.ITermFeatures != nil && cfg.ITermFeatures.Contains(terminal.PromptMark) for i, block := range cfg.Blocks { // only fetch cursor position when relevant diff --git a/src/engine/block.go b/src/engine/block.go index e88543a5..6e380f15 100644 --- a/src/engine/block.go +++ b/src/engine/block.go @@ -4,10 +4,10 @@ import ( "strings" "sync" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/regex" "github.com/jandedobbeleer/oh-my-posh/src/shell" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" ) // BlockType type of block @@ -56,19 +56,19 @@ type Block struct { MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"` env platform.Environment - writer *ansi.Writer + writer *terminal.Writer activeSegment *Segment previousActiveSegment *Segment } -func (b *Block) Init(env platform.Environment, writer *ansi.Writer) { +func (b *Block) Init(env platform.Environment, writer *terminal.Writer) { b.env = env b.writer = writer b.executeSegmentLogic() } func (b *Block) InitPlain(env platform.Environment, config *Config) { - b.writer = &ansi.Writer{ + b.writer = &terminal.Writer{ TerminalBackground: shell.ConsoleBackgroundColor(env, config.TerminalBackground), AnsiColors: config.MakeColors(), TrueColor: env.Flags().TrueColor, @@ -177,17 +177,17 @@ func (b *Block) renderActiveSegment() { b.writeSeparator(false) switch b.activeSegment.style() { case Plain, Powerline: - b.writer.Write(ansi.Background, ansi.Foreground, b.activeSegment.text) + b.writer.Write(terminal.Background, terminal.Foreground, b.activeSegment.text) case Diamond: - background := ansi.Transparent + background := terminal.Transparent if b.previousActiveSegment != nil && b.previousActiveSegment.hasEmptyDiamondAtEnd() { background = b.previousActiveSegment.background() } - b.writer.Write(background, ansi.Background, b.activeSegment.LeadingDiamond) - b.writer.Write(ansi.Background, ansi.Foreground, b.activeSegment.text) + b.writer.Write(background, terminal.Background, b.activeSegment.LeadingDiamond) + b.writer.Write(terminal.Background, terminal.Foreground, b.activeSegment.text) case Accordion: if b.activeSegment.Enabled { - b.writer.Write(ansi.Background, ansi.Foreground, b.activeSegment.text) + b.writer.Write(terminal.Background, terminal.Foreground, b.activeSegment.text) } } b.previousActiveSegment = b.activeSegment @@ -197,7 +197,7 @@ func (b *Block) renderActiveSegment() { func (b *Block) writeSeparator(final bool) { isCurrentDiamond := b.activeSegment.style() == Diamond if final && isCurrentDiamond { - b.writer.Write(ansi.Transparent, ansi.Background, b.activeSegment.TrailingDiamond) + b.writer.Write(terminal.Transparent, terminal.Background, b.activeSegment.TrailingDiamond) return } @@ -207,12 +207,12 @@ func (b *Block) writeSeparator(final bool) { } if isPreviousDiamond && isCurrentDiamond && len(b.activeSegment.LeadingDiamond) == 0 { - b.writer.Write(ansi.Background, ansi.ParentBackground, b.previousActiveSegment.TrailingDiamond) + b.writer.Write(terminal.Background, terminal.ParentBackground, b.previousActiveSegment.TrailingDiamond) return } if isPreviousDiamond && len(b.previousActiveSegment.TrailingDiamond) > 0 { - b.writer.Write(ansi.Transparent, ansi.ParentBackground, b.previousActiveSegment.TrailingDiamond) + b.writer.Write(terminal.Transparent, terminal.ParentBackground, b.previousActiveSegment.TrailingDiamond) } isPowerline := b.activeSegment.isPowerline() @@ -234,7 +234,7 @@ func (b *Block) writeSeparator(final bool) { } if shouldOverridePowerlineLeadingSymbol() { - b.writer.Write(ansi.Transparent, ansi.Background, b.activeSegment.LeadingPowerlineSymbol) + b.writer.Write(terminal.Transparent, terminal.Background, b.activeSegment.LeadingPowerlineSymbol) return } @@ -255,13 +255,13 @@ func (b *Block) writeSeparator(final bool) { return } - bgColor := ansi.Background + bgColor := terminal.Background if final || !isPowerline { - bgColor = ansi.Transparent + bgColor = terminal.Transparent } if b.activeSegment.style() == Diamond && len(b.activeSegment.LeadingDiamond) == 0 { - bgColor = ansi.Background + bgColor = terminal.Background } if b.activeSegment.InvertPowerline { @@ -282,11 +282,11 @@ func (b *Block) adjustTrailingDiamondColorOverrides() { return } - if !strings.Contains(b.previousActiveSegment.TrailingDiamond, ansi.Background) && !strings.Contains(b.previousActiveSegment.TrailingDiamond, ansi.Foreground) { + if !strings.Contains(b.previousActiveSegment.TrailingDiamond, terminal.Background) && !strings.Contains(b.previousActiveSegment.TrailingDiamond, terminal.Foreground) { return } - match := regex.FindNamedRegexMatch(ansi.AnchorRegex, b.previousActiveSegment.TrailingDiamond) + match := regex.FindNamedRegexMatch(terminal.AnchorRegex, b.previousActiveSegment.TrailingDiamond) if len(match) == 0 { return } @@ -294,31 +294,31 @@ func (b *Block) adjustTrailingDiamondColorOverrides() { adjustOverride := func(anchor, override string) { newOverride := override switch override { - case ansi.Foreground: - newOverride = ansi.ParentForeground - case ansi.Background: - newOverride = ansi.ParentBackground + case terminal.Foreground: + newOverride = terminal.ParentForeground + case terminal.Background: + newOverride = terminal.ParentBackground } if override == newOverride { return } - newAnchor := strings.Replace(match[ansi.ANCHOR], override, newOverride, 1) + newAnchor := strings.Replace(match[terminal.ANCHOR], override, newOverride, 1) b.previousActiveSegment.TrailingDiamond = strings.Replace(b.previousActiveSegment.TrailingDiamond, anchor, newAnchor, 1) } - if len(match[ansi.BG]) > 0 { - adjustOverride(match[ansi.ANCHOR], match[ansi.BG]) + if len(match[terminal.BG]) > 0 { + adjustOverride(match[terminal.ANCHOR], match[terminal.BG]) } - if len(match[ansi.FG]) > 0 { - adjustOverride(match[ansi.ANCHOR], match[ansi.FG]) + if len(match[terminal.FG]) > 0 { + adjustOverride(match[terminal.ANCHOR], match[terminal.FG]) } } func (b *Block) getPowerlineColor() string { if b.previousActiveSegment == nil { - return ansi.Transparent + return terminal.Transparent } if b.previousActiveSegment.style() == Diamond && len(b.previousActiveSegment.TrailingDiamond) == 0 { return b.previousActiveSegment.background() @@ -327,7 +327,7 @@ func (b *Block) getPowerlineColor() string { return b.previousActiveSegment.background() } if !b.previousActiveSegment.isPowerline() { - return ansi.Transparent + return terminal.Transparent } return b.previousActiveSegment.background() } diff --git a/src/engine/config.go b/src/engine/config.go index f8d6ba28..f021a976 100644 --- a/src/engine/config.go +++ b/src/engine/config.go @@ -12,12 +12,12 @@ import ( json "github.com/goccy/go-json" yaml "github.com/goccy/go-yaml" "github.com/gookit/goutil/jsonutil" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/segments" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/template" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" toml "github.com/pelletier/go-toml/v2" ) @@ -31,29 +31,29 @@ const ( // Config holds all the theme for rendering the prompt type Config struct { - Version int `json:"version" toml:"version"` - FinalSpace bool `json:"final_space,omitempty" toml:"final_space,omitempty"` - ConsoleTitleTemplate string `json:"console_title_template,omitempty" toml:"console_title_template,omitempty"` - TerminalBackground string `json:"terminal_background,omitempty" toml:"terminal_background,omitempty"` - AccentColor string `json:"accent_color,omitempty" toml:"accent_color,omitempty"` - Blocks []*Block `json:"blocks,omitempty" toml:"blocks,omitempty"` - Tooltips []*Segment `json:"tooltips,omitempty" toml:"tooltips,omitempty"` - TransientPrompt *Segment `json:"transient_prompt,omitempty" toml:"transient_prompt,omitempty"` - ValidLine *Segment `json:"valid_line,omitempty" toml:"valid_line,omitempty"` - ErrorLine *Segment `json:"error_line,omitempty" toml:"error_line,omitempty"` - SecondaryPrompt *Segment `json:"secondary_prompt,omitempty" toml:"secondary_prompt,omitempty"` - DebugPrompt *Segment `json:"debug_prompt,omitempty" toml:"debug_prompt,omitempty"` - Palette ansi.Palette `json:"palette,omitempty" toml:"palette,omitempty"` - Palettes *ansi.Palettes `json:"palettes,omitempty" toml:"palettes,omitempty"` - Cycle ansi.Cycle `json:"cycle,omitempty" toml:"cycle,omitempty"` - ShellIntegration bool `json:"shell_integration,omitempty" toml:"shell_integration,omitempty"` - PWD string `json:"pwd,omitempty" toml:"pwd,omitempty"` - Var map[string]any `json:"var,omitempty" toml:"var,omitempty"` - DisableCursorPositioning bool `json:"disable_cursor_positioning,omitempty" toml:"disable_cursor_positioning,omitempty"` - PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty" toml:"patch_pwsh_bleed,omitempty"` - DisableNotice bool `json:"disable_notice,omitempty" toml:"disable_notice,omitempty"` - AutoUpgrade bool `json:"auto_upgrade,omitempty" toml:"auto_upgrade,omitempty"` - ITermFeatures ansi.ITermFeatures `json:"iterm_features,omitempty" toml:"iterm_features,omitempty"` + Version int `json:"version" toml:"version"` + FinalSpace bool `json:"final_space,omitempty" toml:"final_space,omitempty"` + ConsoleTitleTemplate string `json:"console_title_template,omitempty" toml:"console_title_template,omitempty"` + TerminalBackground string `json:"terminal_background,omitempty" toml:"terminal_background,omitempty"` + AccentColor string `json:"accent_color,omitempty" toml:"accent_color,omitempty"` + Blocks []*Block `json:"blocks,omitempty" toml:"blocks,omitempty"` + Tooltips []*Segment `json:"tooltips,omitempty" toml:"tooltips,omitempty"` + TransientPrompt *Segment `json:"transient_prompt,omitempty" toml:"transient_prompt,omitempty"` + ValidLine *Segment `json:"valid_line,omitempty" toml:"valid_line,omitempty"` + ErrorLine *Segment `json:"error_line,omitempty" toml:"error_line,omitempty"` + SecondaryPrompt *Segment `json:"secondary_prompt,omitempty" toml:"secondary_prompt,omitempty"` + DebugPrompt *Segment `json:"debug_prompt,omitempty" toml:"debug_prompt,omitempty"` + Palette terminal.Palette `json:"palette,omitempty" toml:"palette,omitempty"` + Palettes *terminal.Palettes `json:"palettes,omitempty" toml:"palettes,omitempty"` + Cycle terminal.Cycle `json:"cycle,omitempty" toml:"cycle,omitempty"` + ShellIntegration bool `json:"shell_integration,omitempty" toml:"shell_integration,omitempty"` + PWD string `json:"pwd,omitempty" toml:"pwd,omitempty"` + Var map[string]any `json:"var,omitempty" toml:"var,omitempty"` + DisableCursorPositioning bool `json:"disable_cursor_positioning,omitempty" toml:"disable_cursor_positioning,omitempty"` + PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty" toml:"patch_pwsh_bleed,omitempty"` + DisableNotice bool `json:"disable_notice,omitempty" toml:"disable_notice,omitempty"` + AutoUpgrade bool `json:"auto_upgrade,omitempty" toml:"auto_upgrade,omitempty"` + ITermFeatures terminal.ITermFeatures `json:"iterm_features,omitempty" toml:"iterm_features,omitempty"` // Deprecated OSC99 bool `json:"osc99,omitempty" toml:"osc99,omitempty"` @@ -70,12 +70,12 @@ type Config struct { // MakeColors creates instance of AnsiColors to use in AnsiWriter according to // environment and configuration. -func (cfg *Config) MakeColors() ansi.ColorString { +func (cfg *Config) MakeColors() terminal.ColorString { cacheDisabled := cfg.env.Getenv("OMP_CACHE_DISABLED") == "1" - return ansi.MakeColors(cfg.getPalette(), !cacheDisabled, cfg.AccentColor, cfg.env) + return terminal.MakeColors(cfg.getPalette(), !cacheDisabled, cfg.AccentColor, cfg.env) } -func (cfg *Config) getPalette() ansi.Palette { +func (cfg *Config) getPalette() terminal.Palette { if cfg.Palettes == nil { return cfg.Palette } @@ -472,7 +472,7 @@ func defaultConfig(env platform.Environment, warning bool) *Config { }, }, ConsoleTitleTemplate: "{{ .Shell }} in {{ .Folder }}", - Palette: ansi.Palette{ + Palette: terminal.Palette{ "black": "#262B44", "blue": "#4B95E9", "green": "#59C9A5", diff --git a/src/engine/config_test.go b/src/engine/config_test.go index bd43b7a0..5e765137 100644 --- a/src/engine/config_test.go +++ b/src/engine/config_test.go @@ -3,9 +3,9 @@ package engine import ( "testing" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/mock" "github.com/jandedobbeleer/oh-my-posh/src/platform" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -31,21 +31,21 @@ func TestEscapeGlyphs(t *testing.T) { } func TestGetPalette(t *testing.T) { - palette := ansi.Palette{ + palette := terminal.Palette{ "red": "#ff0000", "blue": "#0000ff", } cases := []struct { Case string - Palettes *ansi.Palettes - Palette ansi.Palette - ExpectedPalette ansi.Palette + Palettes *terminal.Palettes + Palette terminal.Palette + ExpectedPalette terminal.Palette }{ { Case: "match", - Palettes: &ansi.Palettes{ + Palettes: &terminal.Palettes{ Template: "{{ .Shell }}", - List: map[string]ansi.Palette{ + List: map[string]terminal.Palette{ "bash": palette, "zsh": { "red": "#ff0001", @@ -57,9 +57,9 @@ func TestGetPalette(t *testing.T) { }, { Case: "no match, no fallback", - Palettes: &ansi.Palettes{ + Palettes: &terminal.Palettes{ Template: "{{ .Shell }}", - List: map[string]ansi.Palette{ + List: map[string]terminal.Palette{ "fish": palette, "zsh": { "red": "#ff0001", @@ -71,9 +71,9 @@ func TestGetPalette(t *testing.T) { }, { Case: "no match, default", - Palettes: &ansi.Palettes{ + Palettes: &terminal.Palettes{ Template: "{{ .Shell }}", - List: map[string]ansi.Palette{ + List: map[string]terminal.Palette{ "zsh": { "red": "#ff0001", "blue": "#0000fb", diff --git a/src/engine/engine.go b/src/engine/engine.go index e0941ab3..1dbd4bc8 100644 --- a/src/engine/engine.go +++ b/src/engine/engine.go @@ -3,20 +3,20 @@ package engine import ( "strings" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/template" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" ) var ( - cycle *ansi.Cycle = &ansi.Cycle{} + cycle *terminal.Cycle = &terminal.Cycle{} ) type Engine struct { Config *Config Env platform.Environment - Writer *ansi.Writer + Writer *terminal.Writer Plain bool console strings.Builder @@ -94,7 +94,7 @@ func (e *Engine) pwd() { // Backwards compatibility for deprecated OSC99 if e.Config.OSC99 { - e.write(e.Writer.ConsolePwd(ansi.OSC99, "", "", cwd)) + e.write(e.Writer.ConsolePwd(terminal.OSC99, "", "", cwd)) return } diff --git a/src/engine/engine_test.go b/src/engine/engine_test.go index 8975f885..d5e68bac 100644 --- a/src/engine/engine_test.go +++ b/src/engine/engine_test.go @@ -4,10 +4,10 @@ import ( "errors" "testing" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/mock" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/shell" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/stretchr/testify/assert" mock2 "github.com/stretchr/testify/mock" @@ -55,16 +55,16 @@ func TestPrintPWD(t *testing.T) { OSC99 bool }{ {Case: "Empty PWD"}, - {Case: "OSC99", Config: ansi.OSC99, Expected: "\x1b]9;9;pwd\x1b\\"}, - {Case: "OSC7", Config: ansi.OSC7, Expected: "\x1b]7;file://host/pwd\x1b\\"}, - {Case: "OSC51", Config: ansi.OSC51, Expected: "\x1b]51;Auser@host:pwd\x1b\\"}, + {Case: "OSC99", Config: terminal.OSC99, Expected: "\x1b]9;9;pwd\x1b\\"}, + {Case: "OSC7", Config: terminal.OSC7, Expected: "\x1b]7;file://host/pwd\x1b\\"}, + {Case: "OSC51", Config: terminal.OSC51, Expected: "\x1b]51;Auser@host:pwd\x1b\\"}, {Case: "Deprecated OSC99", OSC99: true, Expected: "\x1b]9;9;pwd\x1b\\"}, {Case: "Template (empty)", Config: "{{ if eq .Shell \"pwsh\" }}osc7{{ end }}"}, {Case: "Template (non empty)", Config: "{{ if eq .Shell \"shell\" }}osc7{{ end }}", Expected: "\x1b]7;file://host/pwd\x1b\\"}, { Case: "OSC99 Bash", Pwd: `C:\Users\user\Documents\GitHub\oh-my-posh`, - Config: ansi.OSC99, + Config: terminal.OSC99, Shell: shell.BASH, Expected: "\x1b]9;9;C:\\Users\\user\\Documents\\GitHub\\oh-my-posh\x1b\\", }, @@ -85,7 +85,7 @@ func TestPrintPWD(t *testing.T) { Shell: "shell", }) - writer := &ansi.Writer{} + writer := &terminal.Writer{} writer.Init(shell.GENERIC) engine := &Engine{ Env: env, @@ -115,7 +115,7 @@ func engineRender() { cfg := LoadConfig(env) writerColors := cfg.MakeColors() - writer := &ansi.Writer{ + writer := &terminal.Writer{ TerminalBackground: shell.ConsoleBackgroundColor(env, cfg.TerminalBackground), AnsiColors: writerColors, TrueColor: env.CmdFlags.TrueColor, @@ -188,7 +188,7 @@ func TestGetTitle(t *testing.T) { PWD: tc.Cwd, Folder: "vagrant", }) - writer := &ansi.Writer{} + writer := &terminal.Writer{} writer.Init(shell.GENERIC) engine := &Engine{ Config: &Config{ @@ -247,7 +247,7 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) { Root: tc.Root, HostName: "", }) - writer := &ansi.Writer{} + writer := &terminal.Writer{} writer.Init(shell.GENERIC) engine := &Engine{ Config: &Config{ diff --git a/src/engine/image.go b/src/engine/image.go index 6453bfa4..9fcc5bda 100644 --- a/src/engine/image.go +++ b/src/engine/image.go @@ -35,10 +35,10 @@ import ( "strings" "unicode/utf8" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" fontCLI "github.com/jandedobbeleer/oh-my-posh/src/font" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/esimov/stackblur-go" "github.com/fogleman/gg" @@ -114,7 +114,7 @@ type ImageRenderer struct { CursorPadding int RPromptOffset int BgColor string - Ansi *ansi.Writer + Ansi *terminal.Writer env platform.Environment @@ -428,7 +428,7 @@ func (ir *ImageRenderer) lenWithoutANSI(text string) int { for _, match := range matches { text = strings.ReplaceAll(text, match[str], "") } - stripped := regex.ReplaceAllString(ansi.AnsiRegex, text, "") + stripped := regex.ReplaceAllString(terminal.AnsiRegex, text, "") length := utf8.RuneCountInString(stripped) for _, rune := range stripped { length += ir.runeAdditionalWidth(rune) diff --git a/src/engine/image_test.go b/src/engine/image_test.go index 54024bc6..c860e362 100644 --- a/src/engine/image_test.go +++ b/src/engine/image_test.go @@ -5,9 +5,9 @@ import ( "path/filepath" "testing" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/shell" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" "github.com/stretchr/testify/assert" ) @@ -34,7 +34,7 @@ func runImageTest(config, content string) (string, error) { } defer os.Remove(file.Name()) - writer := &ansi.Writer{} + writer := &terminal.Writer{} writer.Init(shell.GENERIC) image := &ImageRenderer{ AnsiString: content, diff --git a/src/engine/new.go b/src/engine/new.go index 02e8654b..b980839f 100644 --- a/src/engine/new.go +++ b/src/engine/new.go @@ -1,9 +1,9 @@ package engine import ( - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/shell" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" ) // New returns a prompt engine initialized with the @@ -24,7 +24,7 @@ func New(flags *platform.Flags) *Engine { env.Var = cfg.Var flags.HasTransient = cfg.TransientPrompt != nil - ansiWriter := &ansi.Writer{ + ansiWriter := &terminal.Writer{ TerminalBackground: shell.ConsoleBackgroundColor(env, cfg.TerminalBackground), AnsiColors: cfg.MakeColors(), Plain: flags.Plain, diff --git a/src/engine/prompt.go b/src/engine/prompt.go index dd6e37d8..37cf6920 100644 --- a/src/engine/prompt.go +++ b/src/engine/prompt.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/shell" "github.com/jandedobbeleer/oh-my-posh/src/template" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" ) type ExtraPromptType int @@ -104,7 +104,7 @@ func (e *Engine) Primary() string { } // in bash, the entire rprompt needs to be escaped for the prompt to be interpreted correctly // see https://github.com/jandedobbeleer/oh-my-posh/pull/2398 - writer := &ansi.Writer{ + writer := &terminal.Writer{ TrueColor: e.Env.Flags().TrueColor, } writer.Init(shell.GENERIC) diff --git a/src/engine/segment.go b/src/engine/segment.go index b876813b..032283f4 100644 --- a/src/engine/segment.go +++ b/src/engine/segment.go @@ -7,11 +7,11 @@ import ( "strings" "time" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/platform" "github.com/jandedobbeleer/oh-my-posh/src/properties" "github.com/jandedobbeleer/oh-my-posh/src/segments" "github.com/jandedobbeleer/oh-my-posh/src/template" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" c "golang.org/x/text/cases" "golang.org/x/text/language" @@ -43,7 +43,7 @@ type Segment struct { Enabled bool `json:"-" toml:"-"` - colors *ansi.Colors + colors *terminal.Colors env platform.Environment writer SegmentWriter text string @@ -445,7 +445,7 @@ func (segment *Segment) shouldInvokeWithTip(tip string) bool { func (segment *Segment) foreground() string { if segment.colors == nil { - segment.colors = &ansi.Colors{} + segment.colors = &terminal.Colors{} } if len(segment.colors.Foreground) == 0 { @@ -457,7 +457,7 @@ func (segment *Segment) foreground() string { func (segment *Segment) background() string { if segment.colors == nil { - segment.colors = &ansi.Colors{} + segment.colors = &terminal.Colors{} } if len(segment.colors.Background) == 0 { diff --git a/src/properties/map.go b/src/properties/map.go index 5d38565c..03a27eeb 100644 --- a/src/properties/map.go +++ b/src/properties/map.go @@ -3,8 +3,8 @@ package properties import ( "fmt" - "github.com/jandedobbeleer/oh-my-posh/src/ansi" "github.com/jandedobbeleer/oh-my-posh/src/regex" + "github.com/jandedobbeleer/oh-my-posh/src/terminal" ) type Properties interface { @@ -71,7 +71,7 @@ func (m Map) GetColor(property Property, defaultValue string) string { return defaultValue } colorString := fmt.Sprint(val) - if ansi.IsAnsiColorName(colorString) { + if terminal.IsAnsiColorName(colorString) { return colorString } values := regex.FindNamedRegexMatch(`(?P#[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|p:.*)`, colorString) diff --git a/src/ansi/ansi_writer.go b/src/terminal/ansi_writer.go similarity index 99% rename from src/ansi/ansi_writer.go rename to src/terminal/ansi_writer.go index 38e14a48..96370c4f 100644 --- a/src/ansi/ansi_writer.go +++ b/src/terminal/ansi_writer.go @@ -1,4 +1,4 @@ -package ansi +package terminal import ( "fmt" diff --git a/src/ansi/ansi_writer_hyperlink_test.go b/src/terminal/ansi_writer_hyperlink_test.go similarity index 99% rename from src/ansi/ansi_writer_hyperlink_test.go rename to src/terminal/ansi_writer_hyperlink_test.go index 17248282..d2b0cb3d 100644 --- a/src/ansi/ansi_writer_hyperlink_test.go +++ b/src/terminal/ansi_writer_hyperlink_test.go @@ -1,4 +1,4 @@ -package ansi +package terminal import ( "testing" diff --git a/src/ansi/ansi_writer_test.go b/src/terminal/ansi_writer_test.go similarity index 99% rename from src/ansi/ansi_writer_test.go rename to src/terminal/ansi_writer_test.go index 9e91f6bc..043c5ab0 100644 --- a/src/ansi/ansi_writer_test.go +++ b/src/terminal/ansi_writer_test.go @@ -1,4 +1,4 @@ -package ansi +package terminal import ( "testing" diff --git a/src/ansi/colors.go b/src/terminal/colors.go similarity index 99% rename from src/ansi/colors.go rename to src/terminal/colors.go index 6c5590ce..db80b9df 100644 --- a/src/ansi/colors.go +++ b/src/terminal/colors.go @@ -1,4 +1,4 @@ -package ansi +package terminal import ( "fmt" diff --git a/src/ansi/colors_test.go b/src/terminal/colors_test.go similarity index 99% rename from src/ansi/colors_test.go rename to src/terminal/colors_test.go index 9c59a64b..d40d793b 100644 --- a/src/ansi/colors_test.go +++ b/src/terminal/colors_test.go @@ -1,4 +1,4 @@ -package ansi +package terminal import ( "errors" diff --git a/src/ansi/colors_unix.go b/src/terminal/colors_unix.go similarity index 96% rename from src/ansi/colors_unix.go rename to src/terminal/colors_unix.go index bb2be8d5..b2bacf2a 100644 --- a/src/ansi/colors_unix.go +++ b/src/terminal/colors_unix.go @@ -1,6 +1,6 @@ //go:build !windows -package ansi +package terminal import "github.com/jandedobbeleer/oh-my-posh/src/platform" diff --git a/src/ansi/colors_windows.go b/src/terminal/colors_windows.go similarity index 98% rename from src/ansi/colors_windows.go rename to src/terminal/colors_windows.go index e77f29d9..f38e14b1 100644 --- a/src/ansi/colors_windows.go +++ b/src/terminal/colors_windows.go @@ -1,4 +1,4 @@ -package ansi +package terminal import ( "errors" diff --git a/src/ansi/cycle.go b/src/terminal/cycle.go similarity index 88% rename from src/ansi/cycle.go rename to src/terminal/cycle.go index b8e377e6..f095248b 100644 --- a/src/ansi/cycle.go +++ b/src/terminal/cycle.go @@ -1,4 +1,4 @@ -package ansi +package terminal type Cycle []*Colors diff --git a/src/ansi/iterm.go b/src/terminal/iterm.go similarity index 98% rename from src/ansi/iterm.go rename to src/terminal/iterm.go index d2f692a4..84134298 100644 --- a/src/ansi/iterm.go +++ b/src/terminal/iterm.go @@ -1,4 +1,4 @@ -package ansi +package terminal import ( "fmt" diff --git a/src/ansi/palette.go b/src/terminal/palette.go similarity index 99% rename from src/ansi/palette.go rename to src/terminal/palette.go index 1aa033f6..005200d8 100644 --- a/src/ansi/palette.go +++ b/src/terminal/palette.go @@ -1,4 +1,4 @@ -package ansi +package terminal import ( "fmt" diff --git a/src/ansi/palette_test.go b/src/terminal/palette_test.go similarity index 99% rename from src/ansi/palette_test.go rename to src/terminal/palette_test.go index 37e6ad83..80352319 100644 --- a/src/ansi/palette_test.go +++ b/src/terminal/palette_test.go @@ -1,4 +1,4 @@ -package ansi +package terminal import ( "testing" diff --git a/src/ansi/palettes.go b/src/terminal/palettes.go similarity index 91% rename from src/ansi/palettes.go rename to src/terminal/palettes.go index 482585f2..5332158c 100644 --- a/src/ansi/palettes.go +++ b/src/terminal/palettes.go @@ -1,4 +1,4 @@ -package ansi +package terminal type Palettes struct { Template string `json:"template,omitempty" toml:"template,omitempty"`