Назначение префикса и placeholder через переменные оболочки

This commit is contained in:
2026-10-25 23:28:11 +03:00
parent ee9a1597a0
commit a5881619df
4 changed files with 81 additions and 26 deletions
+15 -11
View File
@@ -9,7 +9,7 @@ import (
tea "charm.land/bubbletea/v2"
"charm.land/lipgloss/v2"
"nshell/executor"
"nshell/executor"
)
// Сообщение, которое сигнализирует о завершении работы внешней команды
@@ -21,9 +21,9 @@ type model struct {
errText string // Храним ошибку, если команда не найдена
}
func initialModel() model {
func initialModel(placeholderText string, prefixText string) model {
ti := textinput.New()
ti.Placeholder = "Type a command..."
ti.Placeholder = placeholderText
ti.Focus()
ti.CharLimit = 250
ti.SetWidth(60)
@@ -33,8 +33,7 @@ func initialModel() model {
Foreground(lipgloss.Color("#FF00FA")).
Bold(true)
ti.Prompt = prefixStyle.Render("noko> ")
//prefixStyle=lipgloss.NewStyle().Foreground(lipgloss.Color("#00FFD1"))
ti.Prompt = prefixStyle.Render(prefixText)
return model{
textInput: ti,
@@ -51,7 +50,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "esc":
case "ctrl+c":
m.textInput.SetValue("")
return m, nil
case "ctrl+d":
return m, tea.Quit
case "enter":
@@ -108,22 +110,24 @@ func (m model) View() tea.View {
errStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#FF0000"))
s.WriteString(errStyle.Render(m.errText))
s.WriteString("\n")
m.errText = ""
}
s.WriteString(m.textInput.View())
// Возвращаем объект tea.View, обернув в него строку
return tea.NewView(s.String())
}
func main() {
// Применение setup скрипта
executor.ExecSetUpScript()
placeholderText := executor.GetVariable("NSHELL_NO_TEXT_PLACEHOLDER")
prefixText := executor.GetVariable("NSHELL_PREFIX")
// Запускаем программу
p := tea.NewProgram(initialModel())
p := tea.NewProgram(initialModel(placeholderText, prefixText))
if _, err := p.Run(); err != nil {
fmt.Printf("Error running noko-shell: %v\n", err)
os.Exit(1)
}
}