mdtt

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2024 License: MIT Imports: 28 Imported by: 0

README ΒΆ

πŸ—“οΈ mdtt: Markdown Table Editor TUI

Editing markdown tables can be a drag. mdtt makes it easier with a slick TUI for terminal use and vim-style keybindings. It supports output to stdout and in-place file editing.

πŸ“¦ Installation

To install mdtt using Go, run:

go install github.com/szktkfm/mdtt/cmd/mdtt@latest

Or, download it:

GitHub Releases

🎬 Usage

To start editing your markdown table, simply run:

mdtt filename.md

Upon launching, mdtt will display the tables from your markdown file in a TUI.

While editing, you can utilize the following vim-like keybindings to navigate and modify your tables efficiently:

  • Navigation: Use hjkl for left, down, up, and right movements.
  • Editing: Press i to switch to insert mode and edit cell content, exit insert mode with esc or ctrl+c.
  • Row and Column Manipulation:
    • Add a new row or colymn with o, vo.
    • Delete the current row or column with dd, vd.
    • Copy the current row or column with yy, vy.
    • Paste a copied row or column with p.

For direct editing and saving changes to the same file, use:

mdtt -i filename.md

You can use piping with mdtt as shown below:

pbpaste | mdtt | pbcopy

To create a new table without an existing file, run mdtt without any arguments:

mdtt

When multiple tables are present, you will be prompted to select the table you wish to edit.

Press I to open the cell in the text editor set as your $EDITOR, allowing you to edit the cell directly within your chosen editor.

⌨️ Key Bindings

Key Action
↑/k Move up
↓/j Move down
←/h Move left
β†’/l Move right
b/pgup Page up
f/pgdn Page down
ctrl+u Half page up
ctrl+d Half page down
g/home Go to start
G/end Go to end
i Insert mode
I Open $EDITOR
esc/ctrl+c Normal mode
o/vo Add row/column
dd/vd Delete row/column
yy/vy Copy row/column
p Paste
q Quit
? Toggle help

πŸ“ Features

  • Vim-like Keybindings: Navigate and edit tables using familiar vim commands.
  • Inplace Editing: Directly modify your original markdown files with the -i option.
  • Piping Support
  • Multi-Table Selection
  • External Editor Integration: Delegate cell editing to an external editor specified by your $EDITOR environment variable.
  • HTML in Cells: Enable rich content formatting by using HTML directly within table cells.

πŸ™ Acknowledgments

This project, mdtt, was inspired by mdvtbl, a tool that reads markdown from stdin, allows for table editing in a web view, and outputs to stdout.

License

MIT

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	NORMAL = iota
	INSERT
	HEADER
	HEADER_INSERT
	HELP
)

Enum of Mode

Variables ΒΆ

This section is empty.

Functions ΒΆ

func DefaultColumns ΒΆ

func DefaultColumns() []column

func DefaultRows ΒΆ

func DefaultRows() []naiveRow

func NewCell ΒΆ

func NewCell(value string) cell

func NewHeaderList ΒΆ

func NewHeaderList(opts ...func(*headerList)) headerList

func NewTableModelBuilder ΒΆ

func NewTableModelBuilder() *tableModelBuilder

func WithItems ΒΆ

func WithItems(items []list.Item) func(*headerList)

func WithTables ΒΆ

func WithTables(tables []TableModel) func(*headerList)

func Write ΒΆ

func Write(m Model)

Types ΒΆ

type Model ΒΆ

type Model struct {
	// contains filtered or unexported fields
}

func NewUI ΒΆ

func NewUI(opts ...Option) (Model, error)

func (Model) Init ΒΆ

func (m Model) Init() tea.Cmd

func (Model) Update ΒΆ

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Model) View ΒΆ

func (m Model) View() string

type Option ΒΆ

type Option func(*Model) error

func WithFilePath ΒΆ

func WithFilePath(f string) Option

func WithInplace ΒΆ

func WithInplace(i bool) Option

func WithMarkdown ΒΆ

func WithMarkdown(b []byte) Option

type TableModel ΒΆ

type TableModel struct {
	// contains filtered or unexported fields
}

TableModel defines a state for the table widget.

func NewTableModel ΒΆ

func NewTableModel(opts ...TableOption) TableModel

NewTableModel creates a new model for the table widget.

func (TableModel) Cursor ΒΆ

func (m TableModel) Cursor() int

Cursor returns the index of the selected row.

func (TableModel) Height ΒΆ

func (m TableModel) Height() int

Height returns the viewport height of the table.

func (TableModel) Rows ΒΆ

func (m TableModel) Rows() []row

Rows returns the current rows.

func (TableModel) SelectedRow ΒΆ

func (m TableModel) SelectedRow() row

SelectedRow returns the selected row. You can cast it to your own implementation.

func (*TableModel) SetColumns ΒΆ

func (m *TableModel) SetColumns(c []column)

SetColumns sets a new columns state.

func (*TableModel) SetCursor ΒΆ

func (m *TableModel) SetCursor(n int)

SetCursor sets the cursor.y position in the table.

func (*TableModel) SetHeight ΒΆ

func (m *TableModel) SetHeight(h int)

SetHeight sets the height of the viewport of the table.

func (*TableModel) SetRows ΒΆ

func (m *TableModel) SetRows(r []row)

SetRows sets a new rows state.

func (*TableModel) SetStyles ΒΆ

func (m *TableModel) SetStyles(s tableStyles)

SetStyles sets the table styles.

func (*TableModel) SetWidth ΒΆ

func (m *TableModel) SetWidth(w int)

SetWidth sets the width of the viewport of the table.

func (TableModel) Update ΒΆ

func (m TableModel) Update(msg tea.Msg) (TableModel, tea.Cmd)

Update is the Bubble Tea update loop.

func (TableModel) View ΒΆ

func (m TableModel) View() string

View renders the component.

func (TableModel) Width ΒΆ

func (m TableModel) Width() int

Width returns the viewport width of the table.

type TableOption ΒΆ

type TableOption func(*TableModel)

TableOption is used to set options in New. For example:

table := New(WithColumns([]Column{{Title: "ID", Width: 10}}))

func WithColumns ΒΆ

func WithColumns(cols []column) TableOption

WithColumns sets the table columns (headers).

func WithFocused ΒΆ

func WithFocused(f bool) TableOption

WithFocused sets the focus state of the table.

func WithHeight ΒΆ

func WithHeight(h int) TableOption

WithHeight sets the height of the table.

func WithKeyMap ΒΆ

func WithKeyMap(km keyMap) TableOption

WithKeyMap sets the key map.

func WithNaiveRows ΒΆ

func WithNaiveRows(rows []naiveRow) TableOption

func WithRows ΒΆ

func WithRows(rows []row) TableOption

WithRows sets the table rows (data).

func WithStyles ΒΆ

func WithStyles(s tableStyles) TableOption

WithStyles sets the table styles.

func WithWidth ΒΆ

func WithWidth(w int) TableOption

WithWidth sets the width of the table.

Directories ΒΆ

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL