aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE2
-rw-r--r--acid.go23
-rw-r--r--acid_test.go17
-rw-r--r--terminal.go8
4 files changed, 34 insertions, 16 deletions
diff --git a/LICENSE b/LICENSE
index d48c2ad..2f82d2f 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2024, Přemysl Eric Janouch <p@janouch.name>
+Copyright (c) 2024 - 2025, Přemysl Eric Janouch <p@janouch.name>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
diff --git a/acid.go b/acid.go
index fd6ce76..16322a5 100644
--- a/acid.go
+++ b/acid.go
@@ -30,7 +30,6 @@ import (
"syscall"
ttemplate "text/template"
"time"
- "unicode"
_ "github.com/mattn/go-sqlite3"
"github.com/pkg/sftp"
@@ -1603,18 +1602,15 @@ func (t *Task) CloneURL() string {
}
func shortDurationString(d time.Duration) string {
- rs := []rune(d.Truncate(time.Second).String())
- for i, r := range rs {
- if !unicode.IsLetter(r) {
- continue
- }
- i++
- for i < len(rs) && unicode.IsLetter(rs[i]) {
- i++
- }
- return string(rs[:i])
+ if d.Abs() >= 24*time.Hour {
+ return strconv.FormatInt(int64(d/time.Hour/24), 10) + "d"
+ } else if d.Abs() >= time.Hour {
+ return strconv.FormatInt(int64(d/time.Hour), 10) + "h"
+ } else if d.Abs() >= time.Minute {
+ return strconv.FormatInt(int64(d/time.Minute), 10) + "m"
+ } else {
+ return strconv.FormatInt(int64(d/time.Second), 10) + "s"
}
- return string(rs)
}
func (t *Task) Created() *time.Time {
@@ -1755,8 +1751,11 @@ func dbOpen(path string) error {
`task`, `duration`, `INTEGER NOT NULL DEFAULT 0`); err != nil {
return err
}
+ fallthrough
case 2:
// The next migration goes here, remember to increment the number below.
+ default:
+ return fmt.Errorf("unsupported database version: %d", version)
}
if _, err = tx.Exec(
diff --git a/acid_test.go b/acid_test.go
index 614fd0a..e8bd5c2 100644
--- a/acid_test.go
+++ b/acid_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"testing"
ttemplate "text/template"
+ "time"
)
func TestTemplateQuote(t *testing.T) {
@@ -30,3 +31,19 @@ func TestTemplateQuote(t *testing.T) {
}
}
}
+
+func TestShortDurationString(t *testing.T) {
+ for _, test := range []struct {
+ d time.Duration
+ expect string
+ }{
+ {72 * time.Hour, "3d"},
+ {-3 * time.Hour, "-3h"},
+ {12 * time.Minute, "12m"},
+ {time.Millisecond, "0s"},
+ } {
+ if sd := shortDurationString(test.d); sd != test.expect {
+ t.Errorf("%s = %s; want %s\n", test.d, sd, test.expect)
+ }
+ }
+}
diff --git a/terminal.go b/terminal.go
index 55eabb5..9886ef0 100644
--- a/terminal.go
+++ b/terminal.go
@@ -210,11 +210,13 @@ func (tw *terminalWriter) processParsedCSI(
if len(params) == 0 {
tw.line = tw.lineTop
tw.column = 0
- } else if len(params) >= 2 && params[0] != 0 && params[1] != 0 {
+ } else if len(params) < 2 || params[0] <= 0 || params[1] <= 0 {
+ return false
+ } else if params[0] >= 32766 && params[1] >= 32766 {
+ // Ignore attempts to scan terminal bounds.
+ } else {
tw.line = tw.lineTop + params[0] - 1
tw.column = params[1] - 1
- } else {
- return false
}
return true
case final == 'J': // Erase in Display