// FirstLine read first line from file
512285
func FirstLine(src string) (line string, err error) {
	err = Filter(src, func(_ int, l []byte) (error) {
		line = string(l)

		return io.EOF
	})

	return
}
778403
func (ctx *compctx) ErrorLine() int {
	var n int
	fmt.Sscanf(ctx.Error(), "Error > stdin:%d", &n)
	return n
}
150338
func (bi *BinaryInfo) AllPCsForFileLine(filename string, lineno int) []uint64 {
	r := make([]uint64, 0, 1)
	for _, cu := range bi.compileUnits {
		if cu.lineInfo.Lookup[filename] != nil {
			r = append(r, cu.lineInfo.AllPCsForFileLine(filename, lineno)...)
		}
	}
	return r
}
68445
func (fu fileUtil) ReadByLines(filePath string, handler func(line string) error) error {
	var f *os.File
	var err error
	if f, err = os.Open(filePath); err == nil {
		defer f.Close()
		var line string
		scanner := bufio.NewScanner(f)
		for scanner.Scan() {
			line = scanner.Text()
			err = handler(line)
			if err != nil {
				return err
			}
		}
	}
	return err

}
212084
func (w *writer) writeLine(s string) {
	if !w.inline {
		w.startLine()
	}
	w.write(s)
	w.endLine()
}
233112
func (r *RefErrUnsupportedDetail) Lines() []string {
	lines := []string{
		r.Ref.String(),
		strings.Repeat("^", len(r.Ref[:r.Pos+1].String())),
		fmt.Sprintf("have: %v", r.Have),
	}
	return lines
}
1041957
func (ln *Line) Read() (line string, err error) {
	var anotherLine []rune // For lines got from history.
	var isHistoryUsed bool // If the history has been accessed.
	var action keyAction

	in := bufio.NewReader(term.Input) // Read input.
	esc := make([]byte, 2)            // For escape sequences.
	extEsc := make([]byte, 3)         // Extended escape sequences.

	// Print the primary prompt.
	if err = ln.Prompt(); err != nil {
		return "", err
	}

	// == Detect change of window size.
	winSize := term.DetectWinSize()

	go func() {
		for {
			select {
			case <-winSize.Change: // Wait for.
				_, col, err := ln.ter.GetSize()
				if err != nil {
					ln.buf.columns = col
					ln.buf.refresh()
				}
			}
		}
	}()
	defer winSize.Close()

	for ; ; action = 0 {
		char, _, err := in.ReadRune()
		if err != nil {
			return "", inputError(err.Error())
		}

	_S:
		switch char {
		default:
			if err = ln.buf.insertRune(char); err != nil {
				return "", err
			}
			continue

		case sys.K_RETURN:
			line = ln.buf.toString()

			if ln.useHistory {
				ln.hist.Add(line)
			}
			if _, err = term.Output.Write(CRLF); err != nil {
				return "", outputError(err.Error())
			}
			return strings.TrimSpace(line), nil

		case sys.K_TAB:
			// TODO: disabled by now
			continue

		case sys.K_BACK, sys.K_CTRL_H:
			if err = ln.buf.deleteCharPrev(); err != nil {
				return "", err
			}
			continue

		case sys.K_CTRL_C:
			if err = ln.buf.insertRunes(CtrlC); err != nil {
				return "", err
			}
			if _, err = term.Output.Write(CRLF); err != nil {
				return "", outputError(err.Error())
			}

			ChanCtrlC <- 1 //TODO: is really necessary?

			if err = ln.Prompt(); err != nil {
				return "", err
			}
			continue
		case sys.K_CTRL_D:
			if err = ln.buf.insertRunes(CtrlD); err != nil {
				return "", err
			}
			if _, err = term.Output.Write(CRLF); err != nil {
				return "", outputError(err.Error())
			}

			ln.Restore()
			ChanCtrlD <- 1
			return "", ErrCtrlD

		// Escape sequence
		case sys.K_ESCAPE: // Ctrl+[ ("\x1b" in hexadecimal, "033" in octal)
			if _, err = in.Read(esc); err != nil {
				return "", inputError(err.Error())
			}

			if esc[0] == 79 { // 'O'
				switch esc[1] {
				case 72: // Home: "\x1b O H"
					action = _HOME
					break _S
				case 70: // End: "\x1b O F"
					action = _END
					break _S
				}
			}

			if esc[0] == 91 { // '['
				switch esc[1] {
				case 65: // Up: "\x1b [ A"
					if !ln.useHistory {
						continue
					}
					action = _UP
					break _S
				case 66: // Down: "\x1b [ B"
					if !ln.useHistory {
						continue
					}
					action = _DOWN
					break _S
				case 68: // "\x1b [ D"
					action = _LEFT
					break _S
				case 67: // "\x1b [ C"
					action = _RIGHT
					break _S
				}

				// Extended escape.
				if esc[1] > 48 && esc[1] < 55 {
					if _, err = in.Read(extEsc); err != nil {
						return "", inputError(err.Error())
					}

					if extEsc[0] == 126 { // '~'
						switch esc[1] {
						//case 50: // Insert: "\x1b [ 2 ~"

						case 51: // Delete: "\x1b [ 3 ~"
							if err = ln.buf.deleteChar(); err != nil {
								return "", err
							}
							continue
							//case 53: // RePag: "\x1b [ 5 ~"

							//case 54: // AvPag: "\x1b [ 6 ~"

						}
					}
					if esc[1] == 49 && extEsc[0] == 59 && extEsc[1] == 53 { // "1;5"
						switch extEsc[2] {
						case 68: // Ctrl+left arrow: "\x1b [ 1 ; 5 D"
							// move to last word
							if err = ln.buf.wordBackward(); err != nil {
								return "", err
							}
							continue
						case 67: // Ctrl+right arrow: "\x1b [ 1 ; 5 C"
							// move to next word
							if err = ln.buf.wordForward(); err != nil {
								return "", err
							}
							continue
						}
					}
				}
			}
			continue

		case sys.K_CTRL_T: // Swap actual character by the previous one.
			if err = ln.buf.swap(); err != nil {
				return "", err
			}
			continue

		case sys.K_CTRL_L: // Clear screen.
			if _, err = term.Output.Write(DelScreenToUpper); err != nil {
				return "", err
			}
			if err = ln.Prompt(); err != nil {
				return "", err
			}
			continue
		case sys.K_CTRL_U: // Delete the whole line.
			if err = ln.buf.deleteLine(); err != nil {
				return "", err
			}
			if err = ln.Prompt(); err != nil {
				return "", err
			}
			continue
		case sys.K_CTRL_K: // Delete from current to end of line.
			if err = ln.buf.deleteToRight(); err != nil {
				return "", err
			}
			continue

		case sys.K_CTRL_P: // Up
			if !ln.useHistory {
				continue
			}
			action = _UP
		case sys.K_CTRL_N: // Down
			if !ln.useHistory {
				continue
			}
			action = _DOWN
		case sys.K_CTRL_B: // Left
			action = _LEFT
		case sys.K_CTRL_F: // Right
			action = _RIGHT

		case sys.K_CTRL_A: // Start of line.
			action = _HOME
		case sys.K_CTRL_E: // End of line.
			action = _END
		}

		switch action {
		case _UP, _DOWN: // Up and down arrow: history
			if action == _UP {
				anotherLine, err = ln.hist.Prev()
			} else {
				anotherLine, err = ln.hist.Next()
			}
			if err != nil {
				continue
			}

			// Update the current history entry before to overwrite it with
			// the next one.
			// TODO: it has to be removed before of to be saved the history
			if !isHistoryUsed {
				ln.hist.Add(ln.buf.toString())
			}
			isHistoryUsed = true

			ln.buf.grow(len(anotherLine))
			ln.buf.size = len(anotherLine) + ln.buf.promptLen
			copy(ln.buf.data[ln.lenPS1:], anotherLine)

			if err = ln.buf.refresh(); err != nil {
				return "", err
			}
			continue
		case _LEFT:
			if _, err = ln.buf.backward(); err != nil {
				return "", err
			}
			continue
		case _RIGHT:
			if _, err = ln.buf.forward(); err != nil {
				return "", err
			}
			continue
		case _HOME:
			if err = ln.buf.start(); err != nil {
				return "", err
			}
			continue
		case _END:
			if _, err = ln.buf.end(); err != nil {
				return "", err
			}
			continue
		}
	}
}
340816
func ReadLinesOfFile(filename string) []string {
	content, err := ioutil.ReadFile(filename)
	if err != nil {
		log.Println(err.Error())
	}
	lines := strings.Split(string(content), "\n")
	return lines
}
821291
func NewLine(ter *term.Terminal, ps1, ps2 string, lenAnsi int, hist *history) (*Line, error) {
	if ter.Mode()&term.RawMode == 0 { // the raw mode is not set
		if err := ter.RawMode(); err != nil {
			return nil, err
		}
	}

	lenPS1 := len(ps1) - lenAnsi
	_, col, err := ter.GetSize()
	if err != nil {
		return nil, err
	}

	buf := newBuffer(lenPS1, col)
	buf.insertRunes([]rune(ps1))

	return &Line{
		ter:  ter,
		buf:  buf,
		hist: hist,

		ps1:    ps1,
		ps2:    ps2,
		lenPS1: lenPS1,

		useHistory: hasHistory(hist),
	}, nil
}
447279
func WalkLines(inpReader io.Reader, walkFn WalkLineFn) error {
	reader := bufio.NewReader(inpReader)

	var walkErr error
	line, readErr := ReadLongLine(reader)
	for ; walkErr == nil && readErr == nil; line, readErr = ReadLongLine(reader) {
		walkErr = walkFn(line)
	}

	// if walk returned an error (other than io.EOF)
	// return that error
	if walkErr != nil && walkErr != io.EOF {
		return walkErr
	}

	// otherwise, if there was a read error (except io.EOF), return that
	if readErr != nil && readErr != io.EOF {
		return readErr
	}

	return nil
}
161158
func Line(length int, fn func(start, end int)) {
	procs := runtime.GOMAXPROCS(0)
	counter := length
	partSize := length / procs
	if procs <= 1 || partSize <= procs {
		fn(0, length)
	} else {
		var wg sync.WaitGroup
		for counter > 0 {
			start := counter - partSize
			end := counter
			if start < 0 {
				start = 0
			}
			counter -= partSize
			wg.Add(1)
			go func() {
				defer wg.Done()
				fn(start, end)
			}()
		}

		wg.Wait()
	}
}
1118630
func (d *Dispenser) Line() int {
	if d.cursor < 0 || d.cursor >= len(d.tokens) {
		return 0
	}
	return d.tokens[d.cursor].Line
}
1286288
func (r *Reader) ReadLineString() (line string, err error) {
	b, e := r.ReadLine()
	return string(b), e
}
270499
func (f Files) Lines(path string) []string {
	if f == nil || f[path] == nil {
		return []string{}
	}

	return strings.Split(string(f[path]), "\n")
}
1219470
func Line(prompt string) (string, error) {
	ins := getInstance()
	ins.SetPrompt(prompt)
	return ins.Readline()
}
670333
func readLines(path string) ([]string, error) {
	bytes, err := ioutil.ReadFile(path)
	if err != nil {
		return nil, fmt.Errorf("could not open file %s: %v", path, err)
	}
	rawLines := strings.Split(string(bytes), "\n")
	var trimmedLines []string
	for _, line := range rawLines {
		if len(strings.TrimSpace(line)) > 0 {
			trimmedLines = append(trimmedLines, strings.TrimSpace(line))
		}
	}
	return trimmedLines, nil
}
257636
func ReadLinesFromReader(r io.Reader) ([]string, error) {
	res := make([]string, 0)
	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		res = append(res, scanner.Text())
	}

	if err := scanner.Err(); err != nil {
		return res, err
	}
	return res, nil
}