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 (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"log"
|
||||
table "git.sealight.xyz/aynish/poms/table"
|
||||
task "git.sealight.xyz/aynish/poms/task"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
task "git.sealight.xyz/aynish/poms/task"
|
||||
table "git.sealight.xyz/aynish/poms/table"
|
||||
)
|
||||
|
||||
|
||||
var (
|
||||
tasks = task.GetTasks()
|
||||
columns = []table.Column{
|
||||
{Title: "ID", Width: 4},
|
||||
{Title: "Project", Width: 20},
|
||||
{Title: "Tags", Width: 40},
|
||||
{Title: "Description", Width: 95},
|
||||
{Title: "Tags", Width: 20},
|
||||
{Title: "Description", Width: 35},
|
||||
// {Title: "Urgency", Width: 10},
|
||||
}
|
||||
|
||||
|
@ -79,7 +78,7 @@ func (m model) rowsToFile() []string {
|
|||
if index < m.taskList.ActiveIndex() {
|
||||
// get uuid
|
||||
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 {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -95,9 +94,9 @@ func (m model) rowsToFile() []string {
|
|||
path := time.Now().Format(time.DateOnly)
|
||||
tags := strings.Replace(row[2], " ", ":", -1)
|
||||
tags = ":" + row[1] + ":" + tags + ":"
|
||||
fmt.Fprintln(f, "%title " + row[3])
|
||||
fmt.Fprintln(f, "%title "+row[3])
|
||||
fmt.Fprintln(f, tags)
|
||||
fmt.Fprintln(f, "%date " + path)
|
||||
fmt.Fprintln(f, "%date "+path)
|
||||
fmt.Fprintln(f, "")
|
||||
f.Close()
|
||||
}
|
||||
|
@ -126,7 +125,7 @@ func (m model) writeFile() string {
|
|||
defer f.Close()
|
||||
fmt.Fprintln(f, "%title ")
|
||||
fmt.Fprintln(f, ":pom:priv:plan:")
|
||||
fmt.Fprintln(f, "%date " + path)
|
||||
fmt.Fprintln(f, "%date "+path)
|
||||
fmt.Fprintln(f, "")
|
||||
|
||||
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
|
||||
// Constant runtime, independent of number of rows in a table.
|
||||
// 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 {
|
||||
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 {
|
||||
m.start = 0
|
||||
m.start = 0 + m.activeIndex
|
||||
}
|
||||
m.end = clamp(m.cursor+m.viewport.Height, m.cursor, len(m.rows))
|
||||
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
|
||||
// and are still adding
|
||||
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[m.activeIndex] = selectedRow
|
||||
m.rows = newSelection
|
||||
m.activeIndex += 1
|
||||
} else {
|
||||
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[m.activeIndex] = selectedRow
|
||||
m.rows = newSelection
|
||||
|
@ -396,10 +401,10 @@ func (m *Model) MoveUp(n int) {
|
|||
switch {
|
||||
case m.start == 0:
|
||||
m.viewport.SetYOffset(clamp(m.viewport.YOffset, 0, m.cursor))
|
||||
case m.start < m.viewport.Height:
|
||||
m.viewport.YOffset = (clamp(clamp(m.viewport.YOffset+n, 0, m.cursor), 0, m.viewport.Height))
|
||||
case m.viewport.YOffset >= 1:
|
||||
m.viewport.YOffset = clamp(m.viewport.YOffset+n, 1, 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))
|
||||
//case m.viewport.YOffset >= 1:
|
||||
// m.viewport.YOffset = clamp(m.viewport.YOffset+n, 1, m.viewport.Height)
|
||||
}
|
||||
m.UpdateViewport()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue