Skip to content
Myr

Remove an extraneous argument and auto-add a trailing newline to views

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Rocha · committed by Christian Rocha · parent e92a2fe · Browse files · 2 files+6 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+6 added−6 removed

  • other:+6 added−6 removed

2 files+6 added−6 removed

modified:examples/simple/main.go+1 added-1 removed
33 unmodified lines
34}3536func view(mdl tea.Model) string {37 m, _ := mdl.(model)38 return fmt.Sprintf("Hi. This program will exit in %d seconds...\n", m)38 return fmt.Sprintf("Hi. This program will exit in %d seconds...", m)39}4041func tick(_ tea.Model) tea.Msg {42 time.Sleep(time.Second)
2 unmodified lines
modified:tea.go+5 added-5 removed
83 unmodified lines
84 }()8586 // Render initial view87 hideCursor()88 p.render(model, true)88 p.render(model)8990 // Subscribe to user input91 // TODO: should we move this to the end-user program level or just keep this92 // here, since it blocks nicely and user input will probably be something
44 unmodified lines
137 }138139 model, cmd = p.update(msg, model)140 cmds <- cmd // process command (if any)141 p.render(model, false)141 p.render(model)142 p.model = model143 }144 }145}146147// Render a view to the terminal148func (p *Program) render(model Model, init bool) {149 view := p.view(model)148func (p *Program) render(model Model) {149 view := p.view(model) + "\n"150151 // We need to add carriage returns to ensure that the cursor travels to the152 // start of a column after a newline153 view = strings.Replace(view, "\n", "\r\n", -1)154155 if !init {155 if linesRendered > 0 {156 clearLines(linesRendered)157 }158 io.WriteString(p.rw, view)159 linesRendered = strings.Count(view, "\r\n")
42 unmodified lines