program

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockPgm

type BlockPgm struct {
	base.BlockBase
	// contains filtered or unexported fields
}

BlockPgm is input to execution.

func NewBlockPgm

func NewBlockPgm(code string) *BlockPgm

NewBlockPgm returns a block with the given code.

func NewBlockPgmFromBlockTut

func NewBlockPgmFromBlockTut(b *model.BlockTut) *BlockPgm

NewBlockPgmFromBlockTut converts a BlockTut to a BlockPgm.

func NewEmptyBlockPgm

func NewEmptyBlockPgm() *BlockPgm

NewEmptyBlockPgm returns an empty block.

func (*BlockPgm) HTMLProse

func (x *BlockPgm) HTMLProse() template.HTML

HTMLProse returns HTML that should precede the block.

func (*BlockPgm) ID

func (x *BlockPgm) ID() int

ID returns the block's ID.

func (*BlockPgm) Name

func (x *BlockPgm) Name() string

Name returns the block name.

func (*BlockPgm) Print

func (x *BlockPgm) Print(
	w io.Writer, prefix string, n int, label base.Label, fileName base.FilePath)

Print prints the block.

type LessonPgm

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

LessonPgm has a one to one correspondence to a file.

func NewLessonPgm

func NewLessonPgm(p base.FilePath, blocks []*BlockPgm) *LessonPgm

NewLessonPgm is a ctor.

func (*LessonPgm) Blocks

func (l *LessonPgm) Blocks() []*BlockPgm

Blocks is all the code blocks extracted from the markdown.

func (*LessonPgm) Name

func (l *LessonPgm) Name() string

Name of the LessonPgm.

func (*LessonPgm) Path

func (l *LessonPgm) Path() base.FilePath

Path of the file that holds the raw markdown for the lesson.

func (*LessonPgm) Print

func (l *LessonPgm) Print(w io.Writer, label base.Label, n int)

Print sends contents to the given Writer.

If n <= 0, print everything, else only print the first n blocks.

n is a count not an index, so to print only the first two blocks, pass n==2, not n==1.

type LessonPgmExtractor

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

LessonPgmExtractor extracts all Lessons in depth first order from a Tutorial to create a flat list of lessons. The lessons are edited - only blocks with the given label are carried over into the new extracted lessons. If a lesson has no blocks with the given label, it is completely dropped.

func NewLessonPgmExtractor

func NewLessonPgmExtractor(label base.Label) *LessonPgmExtractor

NewLessonPgmExtractor is a ctor.

func (*LessonPgmExtractor) FirstTitle

func (v *LessonPgmExtractor) FirstTitle() string

FirstTitle is first H1 header taken from the data - used as the overall title.

func (*LessonPgmExtractor) Lessons

func (v *LessonPgmExtractor) Lessons() []*LessonPgm

Lessons found.

func (*LessonPgmExtractor) VisitBlockTut

func (v *LessonPgmExtractor) VisitBlockTut(b *model.BlockTut)

VisitBlockTut does just that.

func (*LessonPgmExtractor) VisitCourse

func (v *LessonPgmExtractor) VisitCourse(c *model.Course)

VisitCourse does just that.

func (*LessonPgmExtractor) VisitLessonTut

func (v *LessonPgmExtractor) VisitLessonTut(l *model.LessonTut)

VisitLessonTut does just that.

func (*LessonPgmExtractor) VisitTopCourse

func (v *LessonPgmExtractor) VisitTopCourse(t *model.TopCourse)

VisitTopCourse does just that.

type Program

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

Program is a list of Lessons and a label. Each LessonPgm represents a file, so a Program is a collection of N files. Every BlockTut in every lesson is known to have the given label.

func NewProgram

func NewProgram(lessons []*LessonPgm) *Program

NewProgram returns a program with the given lessons.

func NewProgramFromTutorial

func NewProgramFromTutorial(l base.Label, t model.Tutorial) *Program

NewProgramFromTutorial builds a program from blocks extracted from a tutorial.

func (*Program) Label

func (p *Program) Label() base.Label

Label used to extract the Program.

func (*Program) Lessons

func (p *Program) Lessons() []*LessonPgm

Lessons found in the program - a lesson corresponds to a file.

func (Program) PrintNormal

func (p Program) PrintNormal(w io.Writer)

PrintNormal simply prints the contents of a program.

func (Program) PrintPreambled

func (p Program) PrintPreambled(w io.Writer, n int)

PrintPreambled emits the first n blocks of a file normally, then emits the n blocks _again_, as well as all the remaining blocks from remaining files, so that they run in a subshell with signal handling.

This allows the aggregate command sequence (series of command blocks) to be structured as 1) a preamble initialization that impacts the environment of the active shell, followed by 2) everything else executing in a subshell that exits on error. That way, an exit in (2) won't cause the active shell to close. This is annoying if one is running the sequence in a terminal.

It's up to the markdown author to assure that the n blocks can always complete without exit on error because they will run in the existing terminal. These blocks should just set environment variables and/or define shell functions.

The goal is to let the user both modify their existing terminal environment, and run remaining code in a trapped subshell, and survive any errors in that subshell with a modified environment.

Jump to

Keyboard shortcuts

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