Назначение префикса и placeholder через переменные оболочки
This commit is contained in:
+15
-11
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user