refactor: rename ansi to terminal

This commit is contained in:
Jan De Dobbeleer 2024-06-30 20:09:37 +02:00 committed by Jan De Dobbeleer
parent 083625ec85
commit 55c7cf2383
27 changed files with 116 additions and 116 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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

View file

@ -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

View file

@ -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()
}

View file

@ -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",

View file

@ -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",

View file

@ -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
}

View file

@ -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{

View file

@ -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)

View file

@ -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,

View file

@ -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,

View file

@ -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)

View file

@ -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 {

View file

@ -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<color>#[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|p:.*)`, colorString)

View file

@ -1,4 +1,4 @@
package ansi
package terminal
import (
"fmt"

View file

@ -1,4 +1,4 @@
package ansi
package terminal
import (
"testing"

View file

@ -1,4 +1,4 @@
package ansi
package terminal
import (
"testing"

View file

@ -1,4 +1,4 @@
package ansi
package terminal
import (
"fmt"

View file

@ -1,4 +1,4 @@
package ansi
package terminal
import (
"errors"

View file

@ -1,6 +1,6 @@
//go:build !windows
package ansi
package terminal
import "github.com/jandedobbeleer/oh-my-posh/src/platform"

View file

@ -1,4 +1,4 @@
package ansi
package terminal
import (
"errors"

View file

@ -1,4 +1,4 @@
package ansi
package terminal
type Cycle []*Colors

View file

@ -1,4 +1,4 @@
package ansi
package terminal
import (
"fmt"

View file

@ -1,4 +1,4 @@
package ansi
package terminal
import (
"fmt"

View file

@ -1,4 +1,4 @@
package ansi
package terminal
import (
"testing"

View file

@ -1,4 +1,4 @@
package ansi
package terminal
type Palettes struct {
Template string `json:"template,omitempty" toml:"template,omitempty"`