Esempio n. 1
0
func (cl *CommandLine) Draw(draw_cursor bool) {
	cmd_length := cl.get_visible_length()
	cmd := string(cl.Cmd[:cmd_length])
	util.WriteString(cl.X, cl.Y, cl.Length, cl.FG, cl.BG, cl.Prefix)
	util.WriteString_FillWithChar(cl.X+len(cl.Prefix), cl.Y, cl.Length, cl.FG, cl.BG, cmd, cl.FillRune)
	if draw_cursor {
		termbox.SetCursor(cl.X+len(cl.Prefix)+util.Min(cl.cursor_at, cmd_length), cl.Y)
	}
}
Esempio n. 2
0
func (tb *TextBox) draw_question() {
	startx := tb.X + 2
	starty := tb.Y + 2
	stopx := tb.X + tb.Width - 2
	line_width := stopx - startx
	question_array := []rune(tb.question)

	for i := starty; len(question_array) > 0; i++ {
		str_len := util.Min(line_width, len(question_array))
		str := string(question_array[:str_len])
		util.WriteString(startx, i, line_width, termbox.ColorWhite, termbox.ColorBlue, str)
		question_array = question_array[str_len:]
	}
}
Esempio n. 3
0
func (pl *PrintableListing) PrintListing() {
	var dir_header_fg termbox.Attribute
	if pl.filter_nomatch {
		dir_header_fg = termbox.ColorRed
	} else {
		dir_header_fg = termbox.ColorWhite
	}

	pl.col_at = pl.calc_start_column()
	util.WriteString(0, 0, pl.width, dir_header_fg, termbox.ColorBlue, pl.header)
	pl.rows = pl.height - 1
	pl.cols = (pl.items.Len() / pl.height) + 1
	max_cols := (pl.width / pl.column_width) + 1
	available_boxes := max_cols * pl.rows
	start_at := pl.col_at * pl.rows

	var i int = 0
	for e := pl.items.Front(); i-start_at < available_boxes; {
		if i < start_at {
			i++
			if e == nil {
				panic(errors.New(fmt.Sprintf("col_at: %d", pl.col_at)))
			}
			e = e.Next()
			continue // Fast forward
		}

		effective_index := i - start_at

		if e != nil {
			pl.print_entry(
				effective_index%pl.rows, effective_index/pl.rows,
				e, e == pl.highlighted_element)

			e = e.Next()
		} else {
			col := effective_index / pl.rows
			row := effective_index % pl.rows
			str_width := util.Min(pl.column_width, pl.width-(col*pl.column_width))
			util.WriteString(
				col*pl.column_width, row+1, str_width,
				termbox.ColorBlack, termbox.ColorBlack, "")
		}
		i++
	}
}
Esempio n. 4
0
func CreateTextBox(question string, maxwidth, maxheight int) (*TextBox, error) {
	if maxheight < box_minheight {
		return nil, errors.New(fmt.Sprintf("TextBoxes need at least %d rows", box_minheight))
	}
	var tb TextBox
	tb.question = question

	startx := tb.X + 2
	stopx := tb.X + tb.Width - 2
	effective_width := stopx - startx
	question_rows := (effective_width / len(tb.question)) + 1
	needed_rows := question_rows + vertical_overhead
	if needed_rows > maxheight {
		return nil, errors.New(fmt.Sprintf(
			"Not enough room provided for textbox. maxwidth:%d maxheight:%d needed_rows:%d",
			maxwidth, maxheight, needed_rows))
	}
	if question_rows > 1 {
		tb.Width = maxwidth
	} else {
		tb.Width = len(tb.question) + horizontal_overhead
		if tb.Width < comfortable_width {
			tb.Width = util.Min(maxwidth, comfortable_width)
		}
	}
	tb.Height = question_rows + vertical_overhead

	tb.cl = &CommandLine{
		Length:   tb.Width - 4,
		FG:       termbox.ColorWhite,
		BG:       termbox.ColorRed,
		Prefix:   "",
		FillRune: '_',
		Cmd:      make([]rune, 0, 8),
	}

	TextBoxIsOpen = true
	return &tb, nil
}
Esempio n. 5
0
func (cl *CommandLine) get_visible_length() int {
	max_length := cl.Length - len(cl.Prefix) - 1
	return util.Min(len(cl.Cmd), max_length)
}