// renderTerminal returns a string representation of a fully rendered table,
// drawn out for display, with embedded newlines.
437993
func (t *Table) renderTerminal() string {
	// Use a placeholder rather than adding titles/headers to the tables
	// elements or else successive calls will compound them.
	tt := t.clone()

	// Initial top line.
	if !tt.Style.SkipBorder {
		if tt.title != nil && tt.headers == nil {
			tt.elements = append([]Element{&Separator{where: LINE_SUBTOP}}, tt.elements...)
		} else if tt.title == nil && tt.headers == nil {
			tt.elements = append([]Element{&Separator{where: LINE_TOP}}, tt.elements...)
		} else {
			tt.elements = append([]Element{&Separator{where: LINE_INNER}}, tt.elements...)
		}
	}

	// If we have headers, include them.
	if tt.headers != nil {
		ne := make([]Element, 2)
		ne[1] = CreateRow(tt.headers)
		if tt.title != nil {
			ne[0] = &Separator{where: LINE_SUBTOP}
		} else {
			ne[0] = &Separator{where: LINE_TOP}
		}
		tt.elements = append(ne, tt.elements...)
	}

	// If we have a title, write it.
	if tt.title != nil {
		// Match changes to this into renderMarkdown too.
		tt.titleCell = CreateCell(tt.title, &CellStyle{Alignment: AlignCenter, ColSpan: 999})
		ne := []Element{
			&StraightSeparator{where: LINE_TOP},
			CreateRow([]interface{}{tt.titleCell}),
		}
		tt.elements = append(ne, tt.elements...)
	}

	// Create a new table from the
	// generate the runtime style. Must include all cells being printed.
	style := createRenderStyle(tt)

	// Loop over the elements and render them.
	b := bytes.NewBuffer(nil)
	for _, e := range tt.elements {
		b.WriteString(e.Render(style))
		b.WriteString("\n")
	}

	// Add bottom line.
	if !style.SkipBorder {
		b.WriteString((&Separator{where: LINE_BOTTOM}).Render(style) + "\n")
	}

	return b.String()
}
94275
func (t *Template) RenderString(context ...interface{}) (string, error) {
	b := &bytes.Buffer{}
	err := t.Render(b, context...)
	return b.String(), err
}
182946
func RenderScript(cfg cloudinit.RenderConfig, ds ...Decorator) ([]byte, error) {
	out, err := cfg.RenderScript()
	if err != nil {
		return nil, err
	}
	return applyDecorators([]byte(out), ds), nil
}
1208745
func (c Category) RenderHTML(buffer *bytes.Buffer, depth int, maxDepth int) {
	// Check to see if this category is a leaf.
	// A leaf category has no other categories as it's children.
	isLeafCategory := true
	for _, child := range c.children {
		if _, ok := child.(*Category); ok {
			isLeafCategory = false
			break
		}
	}

	if maxDepth > 0 {
		must(fmt.Fprintf(buffer, `<div class="console-column" style="flex: %d">`, c.NumLeafNodes()))
		must(fmt.Fprintf(buffer, `<div class="console-top-item">%s</div>`, template.HTMLEscapeString(c.Name)))
		if isLeafCategory {
			must(fmt.Fprintf(buffer, `<div class="console-top-row console-leaf-category">`))
		} else {
			must(fmt.Fprintf(buffer, `<div class="console-top-row">`))
		}
	}

	for _, child := range c.children {
		child.RenderHTML(buffer, depth+1, maxDepth)
	}

	if maxDepth > 0 {
		must(buffer.WriteString(`</div></div>`))
	}
}
732159
func (s Style) WriteDrawingOptionsToRenderer(r Renderer) {
	r.SetClassName(s.GetClassName())
	r.SetStrokeColor(s.GetStrokeColor())
	r.SetStrokeWidth(s.GetStrokeWidth())
	r.SetStrokeDashArray(s.GetStrokeDashArray())
	r.SetFillColor(s.GetFillColor())
}
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
}
966535
func newTerminal(in *os.File) (*terminal, error) {
	term := &terminal{fd: in.Fd()}

	err := syscall.GetConsoleMode(syscall.Handle(term.fd), &term.origMode)
	if err != nil {
		return term, nil
	}
	mode := term.origMode
	term.supportsEditing = true

	// Set new mode flags.
	mode &^= (echoInputFlag | insertModeFlag | lineInputFlag | mouseInputFlag |
		processedInputFlag | windowInputFlag)

	ret, _, err := setConsoleMode.Call(term.fd, uintptr(mode))
	if ret == 0 {
		return nil, err
	}

	return term, nil
}
1187317
func (s *StraightSeparator) Render(style *renderStyle) string {
	// loop over getting dashes
	width := 0
	for i := 0; i < style.columns; i++ {
		width += style.PaddingLeft + style.CellWidth(i) + style.PaddingRight + utf8.RuneCountInString(style.BorderI)
	}

	switch s.where {
	case LINE_TOP:
		return style.BorderTopLeft + strings.Repeat(style.BorderX, width-1) + style.BorderTopRight
	case LINE_INNER, LINE_SUBTOP:
		return style.BorderLeft + strings.Repeat(style.BorderX, width-1) + style.BorderRight
	case LINE_BOTTOM:
		return style.BorderBottomLeft + strings.Repeat(style.BorderX, width-1) + style.BorderBottomRight
	}
	panic("not reached")
}
764885
func (c AcceptInternalCommand) Render() string {
	args := []string{
		"sudo iptables",
		"-I INPUT",
		"-j ACCEPT",
		"-m comment --comment", fmt.Sprintf("'%s'", iptablesInternalComment),
	}
	if c.Protocol != "" {
		args = append(args, "-p", c.Protocol)
	}
	if c.DestinationAddress != "" {
		args = append(args, "-d", c.DestinationAddress)
	}
	if c.DestinationPort > 0 {
		args = append(args, "--dport", fmt.Sprint(c.DestinationPort))
	}
	return strings.Join(args, " ")
}
1161032
func (s *commonStream) RestoreTerminal() {
	if s.state != nil {
		term.RestoreTerminal(s.fd, s.state)
	}
}
1342383
func (t *TemplateRenderable) RenderHTML(_ ...string) template.HTML {
	return template.HTML(t.Render())
}
1173796
func (t *Table) Render() {
	if t.borders.Top {
		t.printLine(true)
	}
	t.printHeading()
	if t.autoMergeCells {
		t.printRowsMergeCells()
	} else {
		t.printRows()
	}
	if !t.rowLine && t.borders.Bottom {
		t.printLine(true)
	}
	t.printFooter()

	if t.caption {
		t.printCaption()
	}
}
127547
func isTerminal(fd int) bool {
	_, err := unix.IoctlGetTermio(fd, unix.TCGETA)
	return err == nil
}
971317
func IsTerminal(stream interface {
	Fd() uintptr
}) bool {
	return terminal.IsTerminal(int(stream.Fd()))
}
1242211
func (r *Renderer) RenderTo(w io.Writer, str ...[]byte) (int, error) {
	err := r.Begin(w)
	var (
		n int
		c int
	)
	for i := 0; err == nil && i < len(str); i++ {
		c, err = w.Write(str[i])
		n += c
	}
	r.End(w)
	return n, err
}
1296354
func (s String) RenderTo(w io.Writer, resolve VariableResolver) error {
	for _, term := range s {
		var value string
		switch t := term.(type) {
		case literal:
			value = string(t)
		case variable:
			if val, ok := resolve(t.Name); ok {
				value = val
			} else if t.HasDefault {
				value = t.Default
			} else {
				return errUnknownVariable{Name: t.Name}
			}
		}
		if _, err := io.WriteString(w, value); err != nil {
			return err
		}
	}
	return nil
}
1290511
func IsTerminal() bool {
	// Windows is always a terminal
	if runtime.GOOS == "windows" {
		return true
	}

	// Same implementation as readline but with our custom fds
	return readline.IsTerminal(int(wrappedstreams.Stdin().Fd())) &&
		(readline.IsTerminal(int(wrappedstreams.Stdout().Fd())) ||
			readline.IsTerminal(int(wrappedstreams.Stderr().Fd())))
}