package main import ( "fmt" "strconv" "strings" ) type Lane struct { Title string `json:"LaneTitle"` Stories []Story `json:"Stories"` Current int `json:"CurrentStory"` // Index of current story storyOff int // offset for the lane slice } func (l *Lane) CreateStory(b *Board) { storyTitle, err := GetAndConfirmCommandLine("Story Title: ") if err != nil { b.SetMessage(err.Error(), true) return } l.Stories = append(l.Stories, MakeStory(storyTitle)) if l.Current < 0 { l.Current = 0 } } // Zeroes out the offset and current values func (l *Lane) ResetLoadPositions() { if len(l.Stories) > 0 { l.Current = 0 } else { l.Current = -1 } l.storyOff = 0 } func (l Lane) Header(width int, selected bool) string { marker := " " color := style.Lane if selected { marker = "*" color = style.LaneSelected } if len(l.Title) > width { return fmt.Sprintf("%s\033[1;7m%*.*s%s%s", style.Lane, width, width, l.Title[:width-1], marker, styleOff) } else { width := width - 2 leftPad := (width - len(l.Title)) / 2 rightPad := width - len(l.Title) - leftPad return fmt.Sprintf("%s %s\033[1;7m%*.*s%s%s%*.*s\033[27m%s %s", style.Lane, color, leftPad-1, leftPad-1, "", l.Title, marker, rightPad, rightPad, "", style.Lane, styleOff) } } func (l Lane) StringSlice(width int, selected bool) []string { out := make([]string, 0, len(l.Stories) * 3 + 1) for i := l.storyOff; i < len(l.Stories); i++ { leadIn := " " if selected && l.Current == i { leadIn = "\033[1m➜ " } out = append(out, fmt.Sprintf("%s%*.*s%s", style.Lane, width, width, " ", styleOff)) title := l.Stories[i].Title pts := strconv.Itoa(l.Stories[i].Points) if pts == "0" || pts[0] == '-' { pts = "" } if len(title) > width-4 { title = title[:width-5] + "…" } out = append(out, fmt.Sprintf("%s %s%s%-*.*s\033[7m%*s\033[27m%s %s", style.Lane, style.Input, leadIn, width-7, width-7, title, 3, pts, style.Lane, styleOff)) } if len(out) > 0 { out = append(out, fmt.Sprintf("%s%*.*s%s", style.Lane, width, width, " ", styleOff)) } return out } func (l *Lane) Update(args []string, b *Board) { location := strings.ToLower(args[0]) switch location { case "title", "t", "name", "n": title, err := GetAndConfirmCommandLine("New lane title: ") if err != nil { b.SetMessage(err.Error(), true) break } l.Title = title b.SetMessage("Lane title updated", false) default: b.SetMessage(fmt.Sprintf("Unknown lane location %q", args[0]), true) } } func MakeLane(title string) Lane { return Lane{title, make([]Story,0,5), -1, 0} }