| 1 | package terminfo |
| 2 | |
| 3 | type stack []interface{} |
| 4 | |
| 5 | func (s *stack) push(v interface{}) { |
| 6 | *s = append(*s, v) |
| 7 | } |
| 8 | |
| 9 | func (s *stack) pop() interface{} { |
| 10 | if len(*s) == 0 { |
| 11 | return nil |
| 12 | } |
| 13 | v := (*s)[len(*s)-1] |
| 14 | *s = (*s)[:len(*s)-1] |
| 15 | return v |
| 16 | } |
| 17 | |
| 18 | func (s *stack) popInt() int { |
| 19 | if i, ok := s.pop().(int); ok { |
| 20 | return i |
| 21 | } |
| 22 | return 0 |
| 23 | } |
| 24 | |
| 25 | func (s *stack) popBool() bool { |
| 26 | if b, ok := s.pop().(bool); ok { |
| 27 | return b |
| 28 | } |
| 29 | return false |
| 30 | } |
| 31 | |
| 32 | func (s *stack) popByte() byte { |
| 33 | if b, ok := s.pop().(byte); ok { |
| 34 | return b |
| 35 | } |
| 36 | return 0 |
| 37 | } |
| 38 | |
| 39 | func (s *stack) popString() string { |
| 40 | if a, ok := s.pop().(string); ok { |
| 41 | return a |
| 42 | } |
| 43 | return "" |
| 44 | } |
| 45 | |
| 46 | func (s *stack) reset() { |
| 47 | *s = (*s)[:0] |
| 48 | } |