// DrawTerminal returns a DrawFunc that draws a progress bar to an io.Writer
// that is assumed to be a terminal (and therefore respects carriage returns).
543814
func DrawTerminal(w io.Writer) DrawFunc {
	return DrawTerminalf(w, func(progress, total int64) string {
		return fmt.Sprintf("%d/%d", progress, total)
	})
}
1107478
func SetRawTerminal(fd uintptr) (*State, error) {
	oldState, err := MakeRaw(fd)
	if err != nil {
		return nil, err
	}
	handleInterrupt(fd, oldState)
	return oldState, err
}
164099
func (e *Entry) Draw(p *Painter) {
	style := "entry"
	if e.IsFocused() {
		style += ".focused"
	}
	p.WithStyle(style, func(p *Painter) {
		s := e.Size()
		e.text.SetMaxWidth(s.X)

		text := e.visibleText()

		p.FillRect(0, 0, s.X, 1)

		switch e.echoMode {
		case EchoModeNormal:
			p.DrawText(0, 0, text)
		case EchoModePassword:
			p.DrawText(0, 0, strings.Repeat("*", len(text)))
		}

		if e.IsFocused() {
			var off int
			if e.echoMode != EchoModeNoEcho {
				off = e.text.CursorPos().X - e.offset
			}
			p.DrawCursor(off, 0)
		}
	})
}
1219510
func IsTerminalWriter(w io.Writer) bool {
	file, ok := w.(*os.File)
	return ok && term.IsTerminal(file.Fd())
}
1076469
func IsTerminal() bool {
	ws := &winsize{}
	isTerm := true
	defer func() {
		if r := recover(); r != nil {
			isTerm = false
		}
	}()
	// This blows up on windows
	retCode, _, _ := syscall.Syscall(syscall.SYS_IOCTL,
		uintptr(syscall.Stdin),
		uintptr(_TIOCGWINSZ),
		uintptr(unsafe.Pointer(ws)))

	if int(retCode) == -1 {
		return false
	}
	return isTerm
}
518501
func IsTerminal(fd uintptr) bool {
	var termios syscall.Termios
	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
	return err == 0
}
1090942
func IsTerminal(file *os.File) bool {
	var termios syscall.Termios
	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, file.Fd(),
		uintptr(syscall.TCGETS), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
	return err == 0
}
535180
func (b *Box) Draw(p *Painter) {
	style := "box"
	if b.IsFocused() {
		style += ".focused"
	}

	p.WithStyle(style, func(p *Painter) {

		sz := b.Size()

		if b.border {
			p.WithStyle(style+".border", func(p *Painter) {
				p.DrawRect(0, 0, sz.X, sz.Y)
			})
			p.WithStyle(style, func(p *Painter) {
				p.WithMask(image.Rect(0, 0, sz.X-1, 1), func(p *Painter) {
					p.DrawText(1, 0, b.title)
				})
			})
			p.FillRect(1, 1, sz.X-2, sz.Y-2)
			p.Translate(1, 1)
			defer p.Restore()
		} else {
			p.FillRect(0, 0, sz.X, sz.Y)
		}

		var off image.Point
		for _, child := range b.children {
			switch b.Alignment() {
			case Horizontal:
				p.Translate(off.X, 0)
			case Vertical:
				p.Translate(0, off.Y)
			}

			p.WithMask(image.Rectangle{
				Min: image.ZP,
				Max: child.Size(),
			}, func(p *Painter) {
				child.Draw(p)
			})

			p.Restore()

			off = off.Add(child.Size())
		}
	})
}
825522
func (p *Progress) Draw(painter *Painter) {
	painter.DrawRune(0, 0, '[')
	painter.DrawRune(p.Size().X-1, 0, ']')

	start := 1
	end := p.Size().X - 1
	curr := int((float64(p.current) / float64(p.max)) * float64(end-start))

	for i := start; i < curr; i++ {
		painter.DrawRune(i, 0, '=')
	}
	for i := curr + start; i < end; i++ {
		painter.DrawRune(i, 0, '-')
	}
	painter.DrawRune(curr, 0, '>')
}
342947
func drawSlider(win *Window, state nstyle.WidgetStates, style *nstyle.Slider, bounds, virtual_cursor rect.Rect, minval, value, maxval float64) {
	out := &win.cmds
	if style.DrawBegin != nil {
		style.DrawBegin(out)
	}
	if style.DrawEnd != nil {
		defer style.DrawEnd(out)
	}
	if style.Draw != nil {
		style.Draw(out, state, style, bounds.Rectangle(), virtual_cursor.Rectangle(), minval, value, maxval)
		return
	}

	var fill rect.Rect
	var bar rect.Rect
	var scursor rect.Rect
	var background *nstyle.Item
	var bar_color color.RGBA
	var cursor *nstyle.Item

	/* select correct slider images/colors */
	if state&nstyle.WidgetStateActive != 0 {
		background = &style.Active
		bar_color = style.BarActive
		cursor = &style.CursorActive
	} else if state&nstyle.WidgetStateHovered != 0 {
		background = &style.Hover
		bar_color = style.BarHover
		cursor = &style.CursorHover
	} else {
		background = &style.Normal
		bar_color = style.BarNormal
		cursor = &style.CursorNormal
	}

	/* calculate slider background bar */
	bar.X = bounds.X
	bar.Y = (bounds.Y + virtual_cursor.H/2) - virtual_cursor.H/8
	bar.W = bounds.W
	bar.H = bounds.H / 6

	/* resize virtual cursor to given size */
	scursor.H = style.CursorSize.Y
	scursor.W = style.CursorSize.X
	scursor.Y = (bar.Y + bar.H/2.0) - scursor.H/2.0
	scursor.X = virtual_cursor.X - (virtual_cursor.W / 2)

	/* filled background bar style */
	fill.W = (scursor.X + (scursor.W / 2.0)) - bar.X

	fill.X = bar.X
	fill.Y = bar.Y
	fill.H = bar.H

	/* draw background */
	if background.Type == nstyle.ItemImage {
		out.DrawImage(bounds, background.Data.Image)
	} else {
		out.FillRect(bounds, style.Rounding, style.BorderColor)
		out.FillRect(shrinkRect(bounds, style.Border), style.Rounding, background.Data.Color)
	}

	/* draw slider bar */
	out.FillRect(bar, style.Rounding, bar_color)

	out.FillRect(fill, style.Rounding, style.BarFilled)

	/* draw cursor */
	if cursor.Type == nstyle.ItemImage {
		out.DrawImage(scursor, cursor.Data.Image)
	} else {
		out.FillCircle(scursor, cursor.Data.Color)
	}
	return
}
1327688
func (c *client) ResizeTerminal(_ context.Context, containerID, processID string, width, height int) error {
	_, p, err := c.getProcess(containerID, processID)
	if err != nil {
		return err
	}

	c.logger.WithFields(logrus.Fields{
		"container": containerID,
		"process":   processID,
		"height":    height,
		"width":     width,
		"pid":       p.pid,
	}).Debug("resizing")
	return p.hcsProcess.ResizeConsole(uint16(width), uint16(height))
}
447640
func DrawBorder(x1, y1, x2, y2 int, fg, bg termbox.Attribute) {
	termbox.SetCell(x1, y1, '╔', fg, bg)
	FillWithChar('═', x1+1, y1, x2-1, y1, fg, bg)
	termbox.SetCell(x2, y1, '╗', fg, bg)

	FillWithChar('║', x1, y1+1, x1, y2-1, fg, bg)
	FillWithChar('║', x2, y1+1, x2, y2-1, fg, bg)

	termbox.SetCell(x1, y2, '╚', fg, bg)
	FillWithChar('═', x1+1, y2, x2-1, y2, fg, bg)
	termbox.SetCell(x2, y2, '╝', fg, bg)
}
883203
func (c *Frame) DrawControl(t termboxControl) {
	ctlX, ctlY := t.GetX(), t.GetY()
	t.SetX((c.GetX() + ctlX))
	t.SetY((c.GetY() + ctlY))
	t.Draw()
	t.SetX(ctlX)
	t.SetY(ctlY)
}
632098
func (i *ASCIIArt) Draw() {
	drawX, drawY := i.x, i.y
	for _, line := range i.contents {
		DrawStringAtPoint(line, drawX, drawY, i.fg, i.bg)
		drawY++
	}
}
556155
func drawButton(out *command.Buffer, bounds rect.Rect, state nstyle.WidgetStates, style *nstyle.Button) *nstyle.Item {
	var background *nstyle.Item
	if state&nstyle.WidgetStateHovered != 0 {
		background = &style.Hover
	} else if state&nstyle.WidgetStateActive != 0 {
		background = &style.Active
	} else {
		background = &style.Normal
	}

	if background.Type == nstyle.ItemImage {
		out.DrawImage(bounds, background.Data.Image)
	} else {
		out.FillRect(bounds, style.Rounding, style.BorderColor)
		out.FillRect(shrinkRect(bounds, style.Border), style.Rounding, background.Data.Color)
	}

	return background
}
1201307
func (p *Painter) DrawCursor(x, y int) {
	wp := p.mapLocalToWorld(image.Point{x, y})
	p.surface.SetCursor(wp.X, wp.Y)
}
785052
func (e *TextEdit) Draw(p *Painter) {
	style := "entry"
	if e.IsFocused() {
		style += ".focused"
	}
	p.WithStyle(style, func(p *Painter) {
		s := e.Size()
		e.text.SetMaxWidth(s.X)

		lines := e.text.SplitByLine()
		for i, line := range lines {
			p.FillRect(0, i, s.X, 1)
			p.DrawText(0, i, line)
		}
		if e.IsFocused() {
			pos := e.text.CursorPos()
			p.DrawCursor(pos.X, pos.Y)
		}
	})
}