Adds mod functionality but doesnt work for saving and loading
This commit is contained in:
parent
31d833b0d7
commit
18cd13fa92
37
cell.go
37
cell.go
|
@ -6,6 +6,13 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
Bold int = 1
|
||||
Faint int = 2
|
||||
Italic int = 3
|
||||
Underline int = 4
|
||||
)
|
||||
|
||||
type cell struct {
|
||||
kind int // Enum for the type of cell
|
||||
rawVal string // A raw string of the value
|
||||
|
@ -16,7 +23,7 @@ type cell struct {
|
|||
}
|
||||
|
||||
func (c cell) String(width int, selected bool) string {
|
||||
mods := ""
|
||||
mods := c.Mods()
|
||||
if selected {
|
||||
mods += "\033[7m"
|
||||
}
|
||||
|
@ -27,6 +34,34 @@ func (c cell) String(width int, selected bool) string {
|
|||
return fmt.Sprintf(format, mods, width, width, c.mask)
|
||||
}
|
||||
|
||||
func (c cell) Mods() string {
|
||||
var o strings.Builder
|
||||
for _, mod := range c.mods {
|
||||
o.WriteString(fmt.Sprintf("\033[%dm", mod))
|
||||
}
|
||||
return o.String()
|
||||
}
|
||||
|
||||
func (c *cell) ToggleMod(mod int) {
|
||||
if mod > 4 || mod < 1 {
|
||||
return
|
||||
}
|
||||
present := false
|
||||
for i, m := range c.mods {
|
||||
if m == mod {
|
||||
if i != len(c.mods)-1 {
|
||||
c.mods[i] = c.mods[len(c.mods)-1]
|
||||
}
|
||||
c.mods = c.mods[:len(c.mods)-1]
|
||||
present = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !present {
|
||||
c.mods = append(c.mods, mod)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cell) Edit(row, col int) {
|
||||
line, err := GetLine(fmt.Sprintf("\033[2KUpdate %c%d: \033[?25h", col+64, row))
|
||||
if err != nil {
|
||||
|
|
8
sheet.go
8
sheet.go
|
@ -212,6 +212,7 @@ func (s *sheet) ZoomOut() {
|
|||
}
|
||||
|
||||
func (s *sheet) TrimSheet() {
|
||||
trimmed := false
|
||||
for rowIndex := s.rows-1; rowIndex > 0; rowIndex-- {
|
||||
remove := true
|
||||
for _, cell := range s.cells[rowIndex] {
|
||||
|
@ -225,6 +226,7 @@ func (s *sheet) TrimSheet() {
|
|||
}
|
||||
s.cells = s.cells[:rowIndex]
|
||||
s.rows--
|
||||
trimmed = true
|
||||
}
|
||||
for colIndex := s.cols-1; colIndex > 0; colIndex-- {
|
||||
remove := true
|
||||
|
@ -241,6 +243,12 @@ func (s *sheet) TrimSheet() {
|
|||
s.cells[i] = s.cells[i][:len(s.cells[i])-1]
|
||||
}
|
||||
s.cols--
|
||||
trimmed = true
|
||||
}
|
||||
if trimmed {
|
||||
s.selection = point{1,1}
|
||||
s.rowOff = 0
|
||||
s.colOff = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
workbook.go
12
workbook.go
|
@ -27,6 +27,10 @@ const (
|
|||
ToBottom rune = 'G'
|
||||
RowStart rune = '^'
|
||||
RowEnd rune = '$'
|
||||
ModBold rune = 'b'
|
||||
ModFaint rune = 'f'
|
||||
ModItalic rune = 'i'
|
||||
ModUnderline rune = 'u'
|
||||
)
|
||||
|
||||
type workbook struct {
|
||||
|
@ -88,6 +92,14 @@ func (w *workbook) Run() {
|
|||
case PasteRelative:
|
||||
w.sheets[w.sheet].PasteRelative()
|
||||
w.sheets[w.sheet].Recalculate()
|
||||
case ModBold:
|
||||
w.sheets[w.sheet].cells[w.sheets[w.sheet].selection.row-1][w.sheets[w.sheet].selection.col-1].ToggleMod(Bold)
|
||||
case ModFaint:
|
||||
w.sheets[w.sheet].cells[w.sheets[w.sheet].selection.row-1][w.sheets[w.sheet].selection.col-1].ToggleMod(Faint)
|
||||
case ModItalic:
|
||||
w.sheets[w.sheet].cells[w.sheets[w.sheet].selection.row-1][w.sheets[w.sheet].selection.col-1].ToggleMod(Italic)
|
||||
case ModUnderline:
|
||||
w.sheets[w.sheet].cells[w.sheets[w.sheet].selection.row-1][w.sheets[w.sheet].selection.col-1].ToggleMod(Underline)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue