Skip to content

Commit 3aeeb90

Browse files
committed
update color arr on static for compose
1 parent a16aefd commit 3aeeb90

2 files changed

Lines changed: 15 additions & 29 deletions

File tree

main.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ type App struct {
230230
backCurrentView bool // отключаем/ключаем возврат
231231

232232
uniquePrefixColorMap map[string]string // карта для хранения уникального цвета для каждого контейнера в стеках compose
233-
uniquePrefixColorArr []string // массив для хранения уникальных цветов
234233
}
235234

236235
func showHelp() {
@@ -654,6 +653,16 @@ var (
654653
ErrInvalidStat = errors.New("invalid stat output")
655654
)
656655

656+
var (
657+
uniquePrefixColorArr = []string{
658+
"\033[32m", // Зеленый
659+
"\033[33m", // Желтый
660+
"\033[34m", // Синий
661+
"\033[35m", // Пурпурный
662+
"\033[36m", // Голубой
663+
}
664+
)
665+
657666
// Определяем название удаленной системы
658667
func remoteGetOS(sshOptions []string) (string, error) {
659668
cmd := exec.Command("ssh", append(sshOptions, "uname", "-s")...)
@@ -710,17 +719,9 @@ func runGoCui(mock bool) {
710719
streamTypeDocker: true,
711720
lastCurrentView: "services",
712721
backCurrentView: false,
722+
uniquePrefixColorMap: make(map[string]string),
713723
}
714724

715-
app.uniquePrefixColorMap = make(map[string]string)
716-
app.uniquePrefixColorArr = append(app.uniquePrefixColorArr,
717-
"\033[32m", // Зеленый
718-
"\033[33m", // Желтый
719-
"\033[34m", // Синий
720-
"\033[35m", // Пурпурный
721-
"\033[36m", // Голубой
722-
)
723-
724725
// Определяем используемую ОС (linux/darwin/*bsd/windows) и архитектуру
725726
app.getOS = runtime.GOOS
726727
app.getArch = runtime.GOARCH
@@ -3356,7 +3357,7 @@ func (app *App) loadDockerContainer(containerizationSystem string) {
33563357
for _, dc := range app.dockerContainers {
33573358
cn := strings.SplitN(dc.name, "] ", 2)[1]
33583359
if cn != "" {
3359-
newColor := app.uniquePrefixColorArr[len(app.uniquePrefixColorMap)%len(app.uniquePrefixColorArr)]
3360+
newColor := uniquePrefixColorArr[len(app.uniquePrefixColorMap)%len(uniquePrefixColorArr)]
33603361
app.uniquePrefixColorMap[cn] = newColor
33613362
}
33623363
}

main_test.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,9 @@ func TestDockerContainer(t *testing.T) {
355355
dateTimeRegex: dateTimeRegex,
356356
integersInputRegex: integersInputRegex,
357357
syslogUnitRegex: syslogUnitRegex,
358+
uniquePrefixColorMap: make(map[string]string),
358359
}
359360

360-
app.uniquePrefixColorMap = make(map[string]string)
361-
app.uniquePrefixColorArr = append(app.uniquePrefixColorArr,
362-
"\033[32m",
363-
"\033[33m",
364-
"\033[34m",
365-
"\033[35m",
366-
"\033[36m",
367-
)
368-
369361
app.loadDockerContainer(app.selectContainerizationSystem)
370362
if len(app.dockerContainers) == 0 {
371363
t.Errorf("Container list is null")
@@ -623,6 +615,7 @@ func TestCommandColor(t *testing.T) {
623615
integersInputRegex: integersInputRegex,
624616
syslogUnitRegex: syslogUnitRegex,
625617
keybindingsEnabled: true,
618+
uniquePrefixColorMap: make(map[string]string),
626619
}
627620

628621
// Читаем содержимое тестируемого файла
@@ -822,17 +815,9 @@ func TestMockInterface(t *testing.T) {
822815
integersInputRegex: integersInputRegex,
823816
syslogUnitRegex: syslogUnitRegex,
824817
keybindingsEnabled: true,
818+
uniquePrefixColorMap: make(map[string]string),
825819
}
826820

827-
app.uniquePrefixColorMap = make(map[string]string)
828-
app.uniquePrefixColorArr = append(app.uniquePrefixColorArr,
829-
"\033[32m",
830-
"\033[33m",
831-
"\033[34m",
832-
"\033[35m",
833-
"\033[36m",
834-
)
835-
836821
app.getOS = runtime.GOOS
837822
app.getArch = runtime.GOARCH
838823

0 commit comments

Comments
 (0)