mdtt

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2025 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.
    • Clear the current cell with x.
    • Copy the current cell with y..

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
x Clear cell
yy/vy Copy row/column
y. Copy cell
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
mdtt command

Jump to

Keyboard shortcuts

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