cmd

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const CHILD_NODE_ID_LENGTH int = 4
View Source
const COLOR_DONE string = "color_done"
View Source
const COLOR_FLAG string = "color_flag"
View Source
const COLOR_ID string = "color_id"
View Source
const COLOR_TODO string = "color_todo"
View Source
const COLOR_UNCATEGORIZED string = "color_uncategorized"
View Source
const CONFIG_FILE_EXT string = "yaml"
View Source
const CONFIG_FILE_NAME string = "user-config"
View Source
const PROJECT_AUTHOR string = "author"
View Source
const PROJECT_FILENAME_MD string = "project_filename_md"
View Source
const PROJECT_FILENAME_PMD string = "project_filename_pmd"
View Source
const ROOT_PROJECT_ID_LENGTH int = 4

Here, the top level node gets an ID of length 4, and the children get an ID of length 4. Each child node will add on it's own ID to the end of the parent's ID, so that if you're interested in finding the information about a given node, even if you only search for the parent, you should see results from it's children. This mya break down a bit if nodes start to get moved around a lot.

Variables

View Source
var (
	// These variables are injected in by the goreleaser build script only for releases
	Version   = "development"
	CommitSHA = "none"
	BuildDate = "unknown"
)

Functions

func CwdHasProject

func CwdHasProject() bool

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func GetConfigDir

func GetConfigDir() string

func RandomId

func RandomId(length int) string

Types

type MdProject

type MdProject struct {
	MdpNode
	Author string
}

func LoadProject

func LoadProject() MdProject

Loads a project from the current working directory.

func NewMdProject

func NewMdProject(projectName string) MdProject

func ProjectFromStr

func ProjectFromStr(b []byte) MdProject

Takes in a string containing the raw JSON of a project file, and returns a MdProject struct.

func (MdProject) Save

func (p MdProject) Save()

func (MdProject) SaveAsMarkdown

func (p MdProject) SaveAsMarkdown()

func (MdProject) SaveAsPmd

func (p MdProject) SaveAsPmd()

func (MdProject) SaveAsPmdBackup

func (p MdProject) SaveAsPmdBackup()

type MdpNode

type MdpNode struct {
	Id           string
	Name         string
	Content      string
	MarkedStatus Status
	CreatedAt    time.Time
	Parent       *MdpNode `json:"-"` // This is a pointer to the parent node. It is not serialized.
	Nodes        []*MdpNode
	TVNode       *tview.TreeNode `json:"-"` // This is a pointer to the tview node that represents this node in the tree. It is not serialized.
}

func NewMdpNode

func NewMdpNode(name string, content string) *MdpNode

Create a new MdpNode with a random ID. It does not have a parent node, and it's status is UNCATEGORIZED.

func (*MdpNode) AddChildNode

func (n *MdpNode) AddChildNode(node *MdpNode)

func (*MdpNode) FindNodeByRelativeId

func (n *MdpNode) FindNodeByRelativeId(nodeId string) *MdpNode

A recursive function to find a given node by ID. It will search all the children and the parents of this node (but not any of the parents children). It will return nil if not found.

func (*MdpNode) GetFQId

func (n *MdpNode) GetFQId() string

Gets the fully qualified (absolute) ID of a given node, recursively. The fully qualified ID is the relative ID concatenated with the relative IDs of all the parents. An example might be "AB12.CD34.EF56", where the relative ID of the same node is "EF56".

func (*MdpNode) GetRelativeId

func (n *MdpNode) GetRelativeId() string

Gets the relative ID of a given node. The relative ID is normally fairly short (4 chars), and does not include information about it's place in the overall hierarchy, although it is unique. An example might be "AB12"

func (*MdpNode) GetStatus

func (n *MdpNode) GetStatus() Status

This is a recursive function that calculates the "true" status of a node. The true status basically relies on the status of the node's children. If the node has no children, then the node's status is the true status. If any child node is FLAG, then it's parent is also FLAG. If the child nodes are all either TODO, DONE or UNCATEGORIZED, then this node CAN be DONE, but is otherwise TODO (as DONE is set manually). Uncategorized basically means that it was inserted automatically by some other means, and we just need to move it to where it goes, at which point it will be changed to TODO.

func (*MdpNode) IsDescendantOf

func (n *MdpNode) IsDescendantOf(node *MdpNode) bool

func (*MdpNode) RemoveChildNodeById

func (n *MdpNode) RemoveChildNodeById(id string)

func (*MdpNode) SetContents

func (n *MdpNode) SetContents(contents string)

func (*MdpNode) SetStatus

func (n *MdpNode) SetStatus(status Status) error

This function will attempt to set the status of a node. It will return an error if the status change is invalid. For example, you cannot set the status of a node to DONE if any of it's children are not already DONE.

func (MdpNode) StyledString

func (n MdpNode) StyledString() string

This returns a node string styled in accordance with https://pkgo.dev/github.com/rivo/tview#hdr-Styles__Colors__and_Hyperlinks

func (MdpNode) ToMarkdown

func (n MdpNode) ToMarkdown(level int) string

Recursive function to convert an MdpNode to Markdown.

func (*MdpNode) ToTviewTreeNode

func (n *MdpNode) ToTviewTreeNode(focusedNodeId string) (*tview.TreeNode, *tview.TreeNode)

A recursive function to build a tview tree from any given MdpNode (including an MdProject). The second returned node is the "focused" node that should be selected when the entire tree is done. It can be nil, and if so, just select the root node, or ignore it.

type Mode

type Mode int
const (
	TREE_NORMAL Mode = iota
	CONTENTS_EDIT
	TREE_MOVE_NODE
	TREE_NEW_NODE
	TREE_RENAME_NODE
)

type Status

type Status int
const (
	UNCATEGORIZED Status = iota
	FLAG
	TODO
	DONE
)

func (Status) Color

func (s Status) Color() string

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳