WIP: almost working selected rows
This commit is contained in:
parent
b6e195c10b
commit
bc7c635aac
21
main.go
21
main.go
|
@ -2,26 +2,25 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
table "git.sealight.xyz/aynish/poms/table"
|
||||||
"log"
|
task "git.sealight.xyz/aynish/poms/task"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
task "git.sealight.xyz/aynish/poms/task"
|
|
||||||
table "git.sealight.xyz/aynish/poms/table"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tasks = task.GetTasks()
|
tasks = task.GetTasks()
|
||||||
columns = []table.Column{
|
columns = []table.Column{
|
||||||
{Title: "ID", Width: 4},
|
{Title: "ID", Width: 4},
|
||||||
{Title: "Project", Width: 20},
|
{Title: "Project", Width: 20},
|
||||||
{Title: "Tags", Width: 40},
|
{Title: "Tags", Width: 20},
|
||||||
{Title: "Description", Width: 95},
|
{Title: "Description", Width: 35},
|
||||||
// {Title: "Urgency", Width: 10},
|
// {Title: "Urgency", Width: 10},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ func (m model) rowsToFile() []string {
|
||||||
if index < m.taskList.ActiveIndex() {
|
if index < m.taskList.ActiveIndex() {
|
||||||
// get uuid
|
// get uuid
|
||||||
id := row[0]
|
id := row[0]
|
||||||
uuid_byte, err := exec.Command("task", "_get", id + ".uuid").Output()
|
uuid_byte, err := exec.Command("task", "_get", id+".uuid").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -95,9 +94,9 @@ func (m model) rowsToFile() []string {
|
||||||
path := time.Now().Format(time.DateOnly)
|
path := time.Now().Format(time.DateOnly)
|
||||||
tags := strings.Replace(row[2], " ", ":", -1)
|
tags := strings.Replace(row[2], " ", ":", -1)
|
||||||
tags = ":" + row[1] + ":" + tags + ":"
|
tags = ":" + row[1] + ":" + tags + ":"
|
||||||
fmt.Fprintln(f, "%title " + row[3])
|
fmt.Fprintln(f, "%title "+row[3])
|
||||||
fmt.Fprintln(f, tags)
|
fmt.Fprintln(f, tags)
|
||||||
fmt.Fprintln(f, "%date " + path)
|
fmt.Fprintln(f, "%date "+path)
|
||||||
fmt.Fprintln(f, "")
|
fmt.Fprintln(f, "")
|
||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
|
@ -126,7 +125,7 @@ func (m model) writeFile() string {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
fmt.Fprintln(f, "%title ")
|
fmt.Fprintln(f, "%title ")
|
||||||
fmt.Fprintln(f, ":pom:priv:plan:")
|
fmt.Fprintln(f, ":pom:priv:plan:")
|
||||||
fmt.Fprintln(f, "%date " + path)
|
fmt.Fprintln(f, "%date "+path)
|
||||||
fmt.Fprintln(f, "")
|
fmt.Fprintln(f, "")
|
||||||
|
|
||||||
rows := m.rowsToFile()
|
rows := m.rowsToFile()
|
||||||
|
|
|
@ -278,10 +278,15 @@ func (m *Model) UpdateViewport() {
|
||||||
// Render only rows from: m.cursor-m.viewport.Height to: m.cursor+m.viewport.Height
|
// Render only rows from: m.cursor-m.viewport.Height to: m.cursor+m.viewport.Height
|
||||||
// Constant runtime, independent of number of rows in a table.
|
// Constant runtime, independent of number of rows in a table.
|
||||||
// Limits the number of renderedRows to a maximum of 2*m.viewport.Height
|
// Limits the number of renderedRows to a maximum of 2*m.viewport.Height
|
||||||
|
if m.activeIndex > 0 {
|
||||||
|
for i := 0; i < m.activeIndex; i++ {
|
||||||
|
renderedRows = append(renderedRows, m.renderRow(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
if m.cursor >= 0 {
|
if m.cursor >= 0 {
|
||||||
m.start = clamp(m.cursor-m.viewport.Height, 0, m.cursor)
|
m.start = clamp(m.cursor-m.viewport.Height, 0, m.cursor) + m.activeIndex
|
||||||
} else {
|
} else {
|
||||||
m.start = 0
|
m.start = 0 + m.activeIndex
|
||||||
}
|
}
|
||||||
m.end = clamp(m.cursor+m.viewport.Height, m.cursor, len(m.rows))
|
m.end = clamp(m.cursor+m.viewport.Height, m.cursor, len(m.rows))
|
||||||
for i := m.start; i < m.end; i++ {
|
for i := m.start; i < m.end; i++ {
|
||||||
|
@ -336,14 +341,14 @@ func (m *Model) SwitchRow() {
|
||||||
// We check equals because if it's on the border, we just moved into selection
|
// We check equals because if it's on the border, we just moved into selection
|
||||||
// and are still adding
|
// and are still adding
|
||||||
if m.cursor >= m.activeIndex {
|
if m.cursor >= m.activeIndex {
|
||||||
newSelection := make([]Row, len(removedRows) + 1)
|
newSelection := make([]Row, len(removedRows)+1)
|
||||||
newSelection = append(removedRows[:m.activeIndex+1], removedRows[m.activeIndex:]...)
|
newSelection = append(removedRows[:m.activeIndex+1], removedRows[m.activeIndex:]...)
|
||||||
newSelection[m.activeIndex] = selectedRow
|
newSelection[m.activeIndex] = selectedRow
|
||||||
m.rows = newSelection
|
m.rows = newSelection
|
||||||
m.activeIndex += 1
|
m.activeIndex += 1
|
||||||
} else {
|
} else {
|
||||||
m.activeIndex -= 1
|
m.activeIndex -= 1
|
||||||
newSelection := make([]Row, len(removedRows) + 1)
|
newSelection := make([]Row, len(removedRows)+1)
|
||||||
newSelection = append(removedRows[:m.activeIndex+1], removedRows[m.activeIndex:]...)
|
newSelection = append(removedRows[:m.activeIndex+1], removedRows[m.activeIndex:]...)
|
||||||
newSelection[m.activeIndex] = selectedRow
|
newSelection[m.activeIndex] = selectedRow
|
||||||
m.rows = newSelection
|
m.rows = newSelection
|
||||||
|
@ -396,10 +401,10 @@ func (m *Model) MoveUp(n int) {
|
||||||
switch {
|
switch {
|
||||||
case m.start == 0:
|
case m.start == 0:
|
||||||
m.viewport.SetYOffset(clamp(m.viewport.YOffset, 0, m.cursor))
|
m.viewport.SetYOffset(clamp(m.viewport.YOffset, 0, m.cursor))
|
||||||
case m.start < m.viewport.Height:
|
//case m.start < m.viewport.Height:
|
||||||
m.viewport.YOffset = (clamp(clamp(m.viewport.YOffset+n, 0, m.cursor), 0, m.viewport.Height))
|
// m.viewport.YOffset = (clamp(clamp(m.viewport.YOffset+n, 0, m.cursor), 0, m.viewport.Height))
|
||||||
case m.viewport.YOffset >= 1:
|
//case m.viewport.YOffset >= 1:
|
||||||
m.viewport.YOffset = clamp(m.viewport.YOffset+n, 1, m.viewport.Height)
|
// m.viewport.YOffset = clamp(m.viewport.YOffset+n, 1, m.viewport.Height)
|
||||||
}
|
}
|
||||||
m.UpdateViewport()
|
m.UpdateViewport()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue