Simplified TUI stuff
This commit is contained in:
parent
79dfe4ed4a
commit
510f9f9648
4 changed files with 32 additions and 127 deletions
|
@ -55,36 +55,8 @@ func (calendar *Calendar) GetCalendarWeek(timestamp time.Time) (int) {
|
|||
return cw
|
||||
}
|
||||
|
||||
// func (calendar *Calendar) GetBufferForWeekCalendar(cw int, data map[string]decimal.Decimal) ([][]string) {
|
||||
// var output string = ""
|
||||
// var bars [][]string
|
||||
// var totalHours = decimal.NewFromInt(0)
|
||||
|
||||
// var days = []string{"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"}
|
||||
// for _, day := range days {
|
||||
// hours := data[day]
|
||||
// totalHours = totalHours.Add(hours)
|
||||
// bar := GetOutputBarForHours(hours)
|
||||
// bars = append(bars, bar)
|
||||
// }
|
||||
|
||||
// output = fmt.Sprintf("CW %02d %s H\n", cw, totalHours.StringFixed(2))
|
||||
// for row := 0; row < len(bars[0]); row++ {
|
||||
// output = fmt.Sprintf("%s%2d │", output, ((6 - row) * 4))
|
||||
// for col := 0; col < len(bars); col++ {
|
||||
// output = fmt.Sprintf("%s%s", output, bars[col][row])
|
||||
// }
|
||||
// output = fmt.Sprintf("%s\n", output)
|
||||
// }
|
||||
// output = fmt.Sprintf("%s └────────────────────────────\n %s %s %s %s %s %s %s",
|
||||
// output, days[0], days[1], days[2], days[3], days[4], days[5], days[6])
|
||||
|
||||
// return output
|
||||
// }
|
||||
|
||||
func (calendar *Calendar) GetTuiBufferForWeekCalendar(cw int, data map[string]decimal.Decimal) (TuiBuffer) {
|
||||
func (calendar *Calendar) GetOutputForWeekCalendar(cw int, data map[string]decimal.Decimal) (string) {
|
||||
var output string = ""
|
||||
buffer := TuiBuffer{}
|
||||
var bars [][]string
|
||||
var totalHours = decimal.NewFromInt(0)
|
||||
|
||||
|
@ -104,22 +76,8 @@ func (calendar *Calendar) GetTuiBufferForWeekCalendar(cw int, data map[string]de
|
|||
}
|
||||
output = fmt.Sprintf("%s\n", output)
|
||||
}
|
||||
output = fmt.Sprintf("%s └────────────────────────────\n %s %s %s %s %s %s %s",
|
||||
output = fmt.Sprintf("%s └────────────────────────────\n %s %s %s %s %s %s %s\n",
|
||||
output, days[0], days[1], days[2], days[3], days[4], days[5], days[6])
|
||||
|
||||
fmt.Printf("%s\n", output)
|
||||
|
||||
row := 0
|
||||
col := 0
|
||||
for _, chr := range output {
|
||||
if(chr == '\n') {
|
||||
row++
|
||||
col = 0
|
||||
continue
|
||||
}
|
||||
|
||||
buffer[row][col] = chr
|
||||
col++
|
||||
}
|
||||
return buffer
|
||||
return output
|
||||
}
|
||||
|
|
26
z/helpers.go
26
z/helpers.go
|
@ -1,6 +1,7 @@
|
|||
package z
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/user"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
@ -98,3 +99,28 @@ func ParseTime(timeStr string) (time.Time, error) {
|
|||
return time.Now(), errors.New("No match")
|
||||
}
|
||||
}
|
||||
|
||||
func OutputAppendRight(leftStr string, rightStr string, pad int) (string) {
|
||||
var output string = ""
|
||||
var rpos int = 0
|
||||
|
||||
left := []rune(leftStr)
|
||||
right := []rune(rightStr)
|
||||
|
||||
for lpos := 0; lpos < len(left); lpos++ {
|
||||
if left[lpos] == '\n' || lpos == (len(left) - 1) {
|
||||
output = fmt.Sprintf("%s%*s", output, pad, "")
|
||||
for rpos = rpos; rpos < len(right); rpos++ {
|
||||
output = fmt.Sprintf("%s%c", output, right[rpos])
|
||||
if right[rpos] == '\n' {
|
||||
rpos++
|
||||
break
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
output = fmt.Sprintf("%s%c", output, left[lpos])
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
|
18
z/stats.go
18
z/stats.go
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/gookit/color"
|
||||
)
|
||||
|
||||
var statsCmd = &cobra.Command{
|
||||
|
@ -37,21 +36,10 @@ var statsCmd = &cobra.Command{
|
|||
data["Sa"], _ = decimal.NewFromString("18.2")
|
||||
data["Su"], _ = decimal.NewFromString("1.0")
|
||||
|
||||
buff := cal.GetTuiBufferForWeekCalendar(1, data)
|
||||
buff2 := cal.GetTuiBufferForWeekCalendar(2, data)
|
||||
out := cal.GetOutputForWeekCalendar(1, data)
|
||||
out2 := cal.GetOutputForWeekCalendar(2, data)
|
||||
|
||||
r := []rune(color.FgLightWhite.Render("A"))
|
||||
for _, bla := range r {
|
||||
fmt.Printf("Char: %c", bla)
|
||||
}
|
||||
|
||||
tui := Tui{}
|
||||
// tui.Init()
|
||||
fmt.Printf("%s\n", tui.Render(100, 10))
|
||||
tui.Merge(buff, 0, 0)
|
||||
tui.Merge(buff2, 0, 48)
|
||||
fmt.Printf("---\n")
|
||||
fmt.Printf("%s\n", tui.Render(100, 10))
|
||||
fmt.Printf("%s\n", OutputAppendRight(out, out2, 10))
|
||||
|
||||
return
|
||||
},
|
||||
|
|
67
z/tui.go
67
z/tui.go
|
@ -1,67 +0,0 @@
|
|||
package z
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const(
|
||||
TUI_ROWS = 200
|
||||
TUI_COLS = 200
|
||||
)
|
||||
|
||||
type TuiBuffer [TUI_ROWS][TUI_COLS]rune
|
||||
|
||||
type Tui struct {
|
||||
Buffer TuiBuffer
|
||||
}
|
||||
|
||||
func (tui *Tui) Init() {
|
||||
for row := 0; row < TUI_ROWS; row++ {
|
||||
for col := 0; col < TUI_COLS; col++ {
|
||||
tui.Buffer[row][col] = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (tui *Tui) Merge(buffer TuiBuffer, x int, y int) (bool) {
|
||||
inputRow := 0
|
||||
inputCol := 0
|
||||
|
||||
for row := x; row < TUI_ROWS; row++ {
|
||||
for col := y; col < TUI_COLS; col++ {
|
||||
if buffer[inputRow][inputCol] != 0 {
|
||||
tui.Buffer[row][col] = buffer[inputRow][inputCol]
|
||||
}
|
||||
inputCol++
|
||||
}
|
||||
inputRow++
|
||||
inputCol = 0
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (tui *Tui) Render(cols int, rows int) (string) {
|
||||
var output string = ""
|
||||
var emptyRow bool = true
|
||||
|
||||
for row := 0; row < rows; row++ {
|
||||
for col := 0; col < cols; col++ {
|
||||
var chr rune = ' '
|
||||
|
||||
if tui.Buffer[row][col] != 0 {
|
||||
chr = tui.Buffer[row][col]
|
||||
emptyRow = false
|
||||
} else {
|
||||
chr = ' '
|
||||
}
|
||||
output = fmt.Sprintf("%s%c", output, chr)
|
||||
}
|
||||
if emptyRow == false {
|
||||
output = fmt.Sprintf("%s\n", output)
|
||||
emptyRow = true
|
||||
}
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
Loading…
Reference in a new issue