cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

Cancel imports at once and line up the import picker

Dami committed c5ee885
commit
c5ee8855e257cbb7452814f599b9df6a0fabe50e
parent
cb70a1abb9c8c70133f3edefa07c873de73d179a
author
Dami <dami.etoile@gmail.com>
7 files changed, +36 -19
Minternal/fileio/csv.go14++++++++------
Minternal/fileio/parquet.go1+
Minternal/fileio/wk1.go1+
Minternal/fileio/xlsx.go3+--
Minternal/fileio/xlsx_test.go2+-
Minternal/ui/transfer.go27+++++++++++++++++++++------
Minternal/ui/transfer_test.go7+++----
M internal/fileio/csv.go +8 -6
M internal/fileio/parquet.go +1 -0
M internal/fileio/wk1.go +1 -0
M internal/fileio/xlsx.go +1 -2
M internal/fileio/xlsx_test.go +1 -1
M internal/ui/transfer.go +21 -6
@@ -125,12 +125,18 @@ func importable() []string {
125125 // too.126126 func (m *Model) openImport() tea.Cmd {127127 var items []pickItem128- for _, name := range importable() {128+ names := importable()129+ lw := 0 // types line up, and sizes after them130+ for _, name := range names {131+ k, _ := fileio.KindOf(name)132+ lw = max(lw, len(k.Label()))133+ }134+ for _, name := range names {129135 k, _ := fileio.KindOf(name)130136 detail, desc := k.Label(), "Import "+name+", "+strings.ToLower(k.Label()[:1])+k.Label()[1:]131137 if st, err := os.Stat(name); err == nil {132- detail += " " + fileSize(st.Size())133- desc += ", " + fileSize(st.Size()) + ", changed " + st.ModTime().Format("Jan 2 15:04")138+ detail = fmt.Sprintf("%-*s %6s", lw, k.Label(), fileSize(st.Size()))139+ desc += ", " + fileSize(st.Size())134140 }135141 items = append(items, pickItem{title: name, name: len(name), detail: detail, desc: desc,136142 pick: func(m *Model) tea.Cmd {
@@ -228,12 +234,12 @@ func (m *Model) importing(msg tea.Msg) (tea.Cmd, bool) {
228234 switch msg := msg.(type) {229235 case tea.KeyPressMsg:230236 if msg.String() == "esc" {231- m.xfer.job.cancel()237+ m.cancelImport()232238 }233239 return nil, true234240 case tea.MouseClickMsg:235241 if msg.Mouse().Y == contextLine {236- m.xfer.job.cancel() // the Esc chip242+ m.cancelImport() // the Esc chip237243 }238244 return nil, true239245 case tea.MouseMsg, tea.PasteMsg:
@@ -242,6 +248,15 @@ func (m *Model) importing(msg tea.Msg) (tea.Cmd, bool) {
242248 return nil, false243249 }244250 251+// cancelImport stops the import at once; its result, if it still252+// arrives, is ignored.253+func (m *Model) cancelImport() {254+ job := m.xfer.job255+ job.cancel()256+ m.xfer.job = nil257+ m.note = "Import of " + filepath.Base(job.name) + " cancelled"258+}259+245260 // handleTransfer handles import and export messages.246261 func (m *Model) handleTransfer(msg tea.Msg) tea.Cmd {247262 switch msg := msg.(type) {
@@ -372,7 +387,7 @@ func (m *Model) importStatus() string {
372387 job := m.xfer.job373388 rows, frac := job.prog.Get()374389 left := m.th.key.Render("Importing " + filepath.Base(job.name))375- right := countRows(rows)390+ right := countRows(rows) + " read"376391 if frac >= 0 {377392 pct := fmt.Sprintf(" %3d%%", int(frac*100))378393 w := clamp(m.width-ansi.StringWidth(left)-ansi.StringWidth(right)-len(pct)-6, 0, 30)
M internal/ui/transfer_test.go +3 -4
@@ -39,7 +39,7 @@ func TestImportPicker(t *testing.T) {
3939 m := newModel()4040 m.runCommand("file.import")4141 got := strings.Join(pickerTitles(t, m), "\n")42- want := "Old.WK1 | Lotus 1-2-3 worksheet 1 B\nsales.csv | Comma-separated values 28 B"42+ want := "Old.WK1 | Lotus 1-2-3 worksheet 1 B\nsales.csv | Comma-separated values 28 B"4343 if got != want {4444 t.Errorf("picker lists\n%s\nwant\n%s", got, want)4545 }
@@ -249,7 +249,7 @@ func TestImportProgress(t *testing.T) {
249249 if l := line(m, contextLine); l != "Importing big.csv… Esc cancel" {250250 t.Errorf("context %q", l)251251 }252- if l := line(m, m.height-1); !strings.HasPrefix(l, "Importing big.csv") || !strings.HasSuffix(l, "1,234 rows") {252+ if l := line(m, m.height-1); !strings.HasPrefix(l, "Importing big.csv") || !strings.HasSuffix(l, "1,234 rows read") {253253 t.Errorf("status %q", l)254254 }255255 if pb := m.View().ProgressBar; pb == nil || pb.State != tea.ProgressBarIndeterminate {
@@ -257,7 +257,7 @@ func TestImportProgress(t *testing.T) {
257257 }258258 prog.Report(4096, 1, 2)259259 l := line(m, m.height-1)260- if l != "Importing big.csv 4,096 rows ━━━━━━━━━━━━━━━─────────────── 50%" {260+ if l != "Importing big.csv 4,096 rows read ━━━━━━━━━━━━━━━─────────────── 50%" {261261 t.Errorf("status %q", l)262262 }263263 if pb := m.View().ProgressBar; pb == nil || pb.Value != 50 {
@@ -272,7 +272,6 @@ func TestImportProgress(t *testing.T) {
272272 if !cancelled {273273 t.Error("Esc didn't cancel")274274 }275- send(m, importedMsg{id: 7, name: "data/big.csv", err: context.Canceled})276275 if m.xfer.job != nil || line(m, contextLine) != "Import of big.csv cancelled" {277276 t.Errorf("after cancel: %q", line(m, contextLine))278277 }