aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

page.go (1810B)


      1 package main
      2 
      3 import "io"
      4 
      5 type trackingWriter struct {
      6 	w   io.Writer
      7 	err error
      8 }
      9 
     10 func newTrackingWriter(w io.Writer) *trackingWriter {
     11 	return &trackingWriter{w: w}
     12 }
     13 
     14 func (w *trackingWriter) Write(p []byte) (int, error) {
     15 	if w.err != nil {
     16 		return 0, w.err
     17 	}
     18 	n, err := w.w.Write(p)
     19 	if err == nil && n != len(p) {
     20 		err = io.ErrShortWrite
     21 	}
     22 	w.err = err
     23 	return n, err
     24 }
     25 
     26 type Page struct {
     27 	Name        string
     28 	Summary     string
     29 	Section     int
     30 	Date        string
     31 	Synopsis    []SynopsisForm
     32 	Description []Block
     33 	Options     []Option
     34 	Sections    []Section
     35 }
     36 
     37 type Section struct {
     38 	Title  string
     39 	Blocks []Block
     40 }
     41 
     42 type BlockKind int
     43 
     44 const (
     45 	BlockParagraph BlockKind = iota
     46 	BlockTaggedList
     47 	BlockSeeAlso
     48 	BlockSubsection
     49 )
     50 
     51 type Block struct {
     52 	Kind    BlockKind
     53 	Inlines []Inline
     54 	Items   []Item
     55 	Refs    []XRef
     56 	Title   string
     57 	Blocks  []Block
     58 }
     59 
     60 type Item struct {
     61 	Label []Inline
     62 	Body  []Inline
     63 }
     64 
     65 type XRef struct {
     66 	Name    string
     67 	Section string
     68 }
     69 
     70 type Option struct {
     71 	Spec     []SynopsisItem
     72 	Desc     string
     73 	Body     []Block
     74 	Key      string
     75 	Group    string /* name shared by a mutually exclusive option set, empty if standalone */
     76 	Required bool   /* set by a trailing ! on the option spec */
     77 }
     78 
     79 type SynopsisForm struct {
     80 	Items []SynopsisItem
     81 }
     82 
     83 type SynopsisItemKind int
     84 
     85 const (
     86 	SynFlag SynopsisItemKind = iota
     87 	SynArg
     88 	SynCommand
     89 	SynLiteral
     90 	SynOptional
     91 	SynPipe
     92 	SynRequiredGroup /* a {-a|-b|-c} mutually exclusive required group */
     93 )
     94 
     95 type SynopsisItem struct {
     96 	Kind     SynopsisItemKind
     97 	Text     string
     98 	Children []SynopsisItem
     99 }
    100 
    101 type InlineKind int
    102 
    103 const (
    104 	InlineText InlineKind = iota
    105 	InlineNm
    106 	InlineEmph
    107 	InlineLiteral
    108 	InlinePath
    109 	InlineXRef
    110 	InlineFlag
    111 )
    112 
    113 type Inline struct {
    114 	Kind     InlineKind
    115 	Text     string
    116 	Section  string
    117 	Children []Inline
    118 }