z_mirror/pesticide

git clone https://git.raiguard.me/z_mirror/pesticide

Caleb HeuerExtract command history to subtype8be16be

trunk
570 B39 linesraw
1package ui
2
3type CommandHistory struct {
4	history []string
5	pos     int
6}
7
8func NewCommandHistory() CommandHistory {
9	return CommandHistory{
10		history: []string{},
11		pos:     0,
12	}
13}
14
15func (c *CommandHistory) Append(item string) {
16	c.history = append(c.history, item)
17	c.pos = len(c.history)
18}
19
20func (c *CommandHistory) Up() {
21	if c.pos == 0 {
22		return
23	}
24	c.pos--
25}
26
27func (c *CommandHistory) Down() {
28	if c.pos > len(c.history)-1 {
29		return
30	}
31	c.pos++
32}
33
34func (c *CommandHistory) Get() string {
35	if c.pos > len(c.history)-1 {
36		return ""
37	}
38	return c.history[c.pos]
39}