Skip to content

Commit 8d5f747

Browse files
buty4649claude
andcommitted
table: ヘッダ下線付きのテーブル/リスト出力に刷新
tabwriter をやめて独自の tablePrinter を導入。go-runewidth で CJK を含むセル幅を正しく計算し、TTY 出力時のみヘッダ行を緑色+下線で 装飾する。列間ギャップと末尾カラムのターミナル幅残り分も下線に 含めて連続した見た目にする。キー/値表示用に newList も追加。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 30cfe0e commit 8d5f747

9 files changed

Lines changed: 308 additions & 71 deletions

File tree

cmd/approval.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66
"strings"
7-
"text/tabwriter"
87

98
"github.com/pepabo/xpoint-cli/internal/xpoint"
109
"github.com/spf13/cobra"
@@ -95,16 +94,14 @@ func runApprovalList(cmd *cobra.Command, args []string) error {
9594
}
9695

9796
return render(res, resolveOutputFormat(approvalListOutput), approvalListJQ, func() error {
98-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
99-
defer w.Flush()
10097
fmt.Fprintf(os.Stdout, "total: %d\n", res.TotalCount)
101-
fmt.Fprintln(w, "DOCID\tSTATUS\tFORM_NAME\tAPPLY_USER\tAPPROVERS\tAPPLY_DATETIME\tTITLE1")
98+
w := newTable(os.Stdout,
99+
"DOCID", "STATUS", "FORM_NAME", "APPLY_USER", "APPROVERS", "APPLY_DATETIME", "TITLE1")
102100
for _, a := range res.ApprovalList {
103-
fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t%s\t%s\n",
104-
a.DocID, a.DisplayStatus, a.FormName, a.ApplyUser,
105-
strings.Join(a.ApprovalUser, ","), a.ApplyDatetime, a.Title1,
106-
)
101+
w.AddRow(a.DocID, a.DisplayStatus, a.FormName, a.ApplyUser,
102+
strings.Join(a.ApprovalUser, ","), a.ApplyDatetime, a.Title1)
107103
}
104+
w.Print()
108105
return nil
109106
})
110107
}

cmd/document.go

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"path/filepath"
1010
"strconv"
1111
"strings"
12-
"text/tabwriter"
1312
"time"
1413

1514
"github.com/pepabo/xpoint-cli/internal/xpoint"
@@ -376,15 +375,13 @@ func runDocumentSearch(cmd *cobra.Command, args []string) error {
376375
}
377376

378377
return render(res, resolveOutputFormat(docSearchOutput), docSearchJQ, func() error {
379-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
380-
defer w.Flush()
381378
fmt.Fprintf(os.Stdout, "total: %d\n", res.TotalCount)
382-
fmt.Fprintln(w, "DOCID\tFORM_NAME\tWRITER\tWRITE_DATETIME\tSTEP\tSTAT\tTITLE1")
379+
w := newTable(os.Stdout,
380+
"DOCID", "FORM_NAME", "WRITER", "WRITE_DATETIME", "STEP", "STAT", "TITLE1")
383381
for _, it := range res.Items {
384-
fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%d\t%d\t%s\n",
385-
it.DocID, it.Form.Name, it.Writer, it.WriteDatetime, it.Step, it.Stat, it.Title1,
386-
)
382+
w.AddRow(it.DocID, it.Form.Name, it.Writer, it.WriteDatetime, it.Step, it.Stat, it.Title1)
387383
}
384+
w.Print()
388385
return nil
389386
})
390387
}
@@ -423,10 +420,9 @@ func runDocumentCreate(cmd *cobra.Command, args []string) error {
423420
}
424421

425422
return render(&view, resolveOutputFormat(docCreateOutput), docCreateJQ, func() error {
426-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
427-
defer w.Flush()
428-
fmt.Fprintln(w, "DOCID\tMESSAGE_TYPE\tMESSAGE\tURL")
429-
fmt.Fprintf(w, "%d\t%d\t%s\t%s\n", view.DocID, view.MessageType, view.Message, view.URL)
423+
w := newTable(os.Stdout, "DOCID", "MESSAGE_TYPE", "MESSAGE", "URL")
424+
w.AddRow(view.DocID, view.MessageType, view.Message, view.URL)
425+
w.Print()
430426
return nil
431427
})
432428
}
@@ -475,10 +471,9 @@ func runDocumentEdit(cmd *cobra.Command, args []string) error {
475471
}
476472

477473
return render(res, resolveOutputFormat(docEditOutput), docEditJQ, func() error {
478-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
479-
defer w.Flush()
480-
fmt.Fprintln(w, "DOCID\tMESSAGE_TYPE\tMESSAGE")
481-
fmt.Fprintf(w, "%d\t%d\t%s\n", res.DocID, res.MessageType, res.Message)
474+
w := newTable(os.Stdout, "DOCID", "MESSAGE_TYPE", "MESSAGE")
475+
w.AddRow(res.DocID, res.MessageType, res.Message)
476+
w.Print()
482477
return nil
483478
})
484479
}
@@ -504,10 +499,9 @@ func runDocumentDelete(cmd *cobra.Command, args []string) error {
504499
}
505500

506501
return render(res, resolveOutputFormat(docDeleteOutput), docDeleteJQ, func() error {
507-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
508-
defer w.Flush()
509-
fmt.Fprintln(w, "MESSAGE_TYPE\tMESSAGE")
510-
fmt.Fprintf(w, "%d\t%s\n", res.MessageType, res.Message)
502+
w := newTable(os.Stdout, "MESSAGE_TYPE", "MESSAGE")
503+
w.AddRow(res.MessageType, res.Message)
504+
w.Print()
511505
return nil
512506
})
513507
}
@@ -603,10 +597,9 @@ func runDocumentCommentAdd(cmd *cobra.Command, args []string) error {
603597
return err
604598
}
605599
return render(res, resolveOutputFormat(docCommentAddOutput), docCommentAddJQ, func() error {
606-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
607-
defer w.Flush()
608-
fmt.Fprintln(w, "DOCID\tSEQ\tMESSAGE_TYPE\tMESSAGE")
609-
fmt.Fprintf(w, "%d\t%d\t%d\t%s\n", res.DocID, res.Seq, res.MessageType, res.Message)
600+
w := newTable(os.Stdout, "DOCID", "SEQ", "MESSAGE_TYPE", "MESSAGE")
601+
w.AddRow(res.DocID, res.Seq, res.MessageType, res.Message)
602+
w.Print()
610603
return nil
611604
})
612605
}
@@ -625,16 +618,15 @@ func runDocumentCommentGet(cmd *cobra.Command, args []string) error {
625618
return err
626619
}
627620
return render(res, resolveOutputFormat(docCommentGetOutput), docCommentGetJQ, func() error {
628-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
629-
defer w.Flush()
630-
fmt.Fprintln(w, "SEQ\tATTENTION\tWRITER\tWRITE_DATE\tCONTENT")
621+
w := newTable(os.Stdout, "SEQ", "ATTENTION", "WRITER", "WRITE_DATE", "CONTENT")
631622
for _, cm := range res.CommentList {
632623
attention := "-"
633624
if cm.AttentionFlg {
634625
attention = "*"
635626
}
636-
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", cm.SeqNo, attention, cm.WriterName, cm.WriteDate, cm.Content)
627+
w.AddRow(cm.SeqNo, attention, cm.WriterName, cm.WriteDate, cm.Content)
637628
}
629+
w.Print()
638630
return nil
639631
})
640632
}
@@ -677,10 +669,9 @@ func runDocumentCommentEdit(cmd *cobra.Command, args []string) error {
677669
return err
678670
}
679671
return render(res, resolveOutputFormat(docCommentEditOutput), docCommentEditJQ, func() error {
680-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
681-
defer w.Flush()
682-
fmt.Fprintln(w, "DOCID\tSEQ\tMESSAGE_TYPE\tMESSAGE")
683-
fmt.Fprintf(w, "%d\t%d\t%d\t%s\n", res.DocID, res.Seq, res.MessageType, res.Message)
672+
w := newTable(os.Stdout, "DOCID", "SEQ", "MESSAGE_TYPE", "MESSAGE")
673+
w.AddRow(res.DocID, res.Seq, res.MessageType, res.Message)
674+
w.Print()
684675
return nil
685676
})
686677
}
@@ -706,10 +697,9 @@ func runDocumentCommentDelete(cmd *cobra.Command, args []string) error {
706697
return err
707698
}
708699
return render(res, resolveOutputFormat(docCommentDeleteOutput), docCommentDeleteJQ, func() error {
709-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
710-
defer w.Flush()
711-
fmt.Fprintln(w, "DOCID\tSEQ\tMESSAGE_TYPE\tMESSAGE")
712-
fmt.Fprintf(w, "%d\t%d\t%d\t%s\n", res.DocID, res.Seq, res.MessageType, res.Message)
700+
w := newTable(os.Stdout, "DOCID", "SEQ", "MESSAGE_TYPE", "MESSAGE")
701+
w.AddRow(res.DocID, res.Seq, res.MessageType, res.Message)
702+
w.Print()
713703
return nil
714704
})
715705
}

cmd/form.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"os"
88
"strconv"
9-
"text/tabwriter"
109

1110
"github.com/pepabo/xpoint-cli/internal/xpoint"
1211
"github.com/spf13/cobra"
@@ -65,18 +64,17 @@ func runFormList(cmd *cobra.Command, args []string) error {
6564
}
6665

6766
return render(res, resolveOutputFormat(formListOutput), formListJQ, func() error {
68-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
69-
defer w.Flush()
70-
fmt.Fprintln(w, "GROUP_ID\tGROUP_NAME\tFORM_ID\tFORM_CODE\tFORM_NAME")
67+
w := newTable(os.Stdout, "GROUP_ID", "GROUP_NAME", "FORM_ID", "FORM_CODE", "FORM_NAME")
7168
for _, g := range res.FormGroup {
7269
if len(g.Form) == 0 {
73-
fmt.Fprintf(w, "%d\t%s\t-\t-\t-\n", g.ID, g.Name)
70+
w.AddRow(g.ID, g.Name, "-", "-", "-")
7471
continue
7572
}
7673
for _, f := range g.Form {
77-
fmt.Fprintf(w, "%d\t%s\t%d\t%s\t%s\n", g.ID, g.Name, f.ID, f.Code, f.Name)
74+
w.AddRow(g.ID, g.Name, f.ID, f.Code, f.Name)
7875
}
7976
}
77+
w.Print()
8078
return nil
8179
})
8280
}
@@ -100,16 +98,13 @@ func runFormShow(cmd *cobra.Command, args []string) error {
10098
return render(res, resolveOutputFormat(formShowOutput), formShowJQ, func() error {
10199
form := res.Form
102100
fmt.Fprintf(os.Stdout, "FORM: %s %s MAX_STEP: %d\n", form.Code, form.Name, form.MaxStep)
103-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
104-
defer w.Flush()
105-
fmt.Fprintln(w, "PAGE\tFIELD_ID\tTYPE\tREQUIRED\tUNIQUE\tARRAYSIZE\tLABEL")
101+
w := newTable(os.Stdout, "PAGE", "FIELD_ID", "TYPE", "REQUIRED", "UNIQUE", "ARRAYSIZE", "LABEL")
106102
for _, p := range form.Pages {
107103
for _, f := range p.Fields {
108-
fmt.Fprintf(w, "%d\t%s\t%d\t%t\t%t\t%d\t%s\n",
109-
p.PageNo, f.FieldID, f.FieldType, f.Required, f.Unique, f.ArraySize, f.Label,
110-
)
104+
w.AddRow(p.PageNo, f.FieldID, f.FieldType, f.Required, f.Unique, f.ArraySize, f.Label)
111105
}
112106
}
107+
w.Print()
113108
return nil
114109
})
115110
}

cmd/me.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"fmt"
55
"os"
6-
"text/tabwriter"
76

87
"github.com/spf13/cobra"
98
)
@@ -48,12 +47,12 @@ func runMe(cmd *cobra.Command, args []string) error {
4847
}
4948

5049
return render(info, resolveOutputFormat(meOutput), meJQ, func() error {
51-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
52-
defer w.Flush()
53-
fmt.Fprintf(w, "user_code:\t%s\n", info.AtledExt.UserCode)
54-
fmt.Fprintf(w, "user_name:\t%s\n", info.UserName)
55-
fmt.Fprintf(w, "display_name:\t%s\n", info.DisplayName)
56-
fmt.Fprintf(w, "scim_id:\t%s\n", info.ID)
50+
w := newList(os.Stdout)
51+
w.AddRow("user_code:", info.AtledExt.UserCode)
52+
w.AddRow("user_name:", info.UserName)
53+
w.AddRow("display_name:", info.DisplayName)
54+
w.AddRow("scim_id:", info.ID)
55+
w.Print()
5756
return nil
5857
})
5958
}

0 commit comments

Comments
 (0)