Skip to content

Instantly share code, notes, and snippets.

@davemackintosh
Last active August 16, 2019 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davemackintosh/1e61422536c2a84e5a6656f568583b6a to your computer and use it in GitHub Desktop.
Save davemackintosh/1e61422536c2a84e5a6656f568583b6a to your computer and use it in GitHub Desktop.
function renderLines(lines: number = 2): number {
const columns = process.stdout.columns
const resultingText = ("a").repeat((columns * lines))
const result = resultingText.length / columns // -- in testing this was like 1.99999467 so I ceil it
return Math.ceil(result) // -- lines
}
function countTextLines(text: string): number {
const columns = process.stdout.columns
const result = text.length / columns // -- in testing this was like 1.99999467 so I ceil it
return Math.ceil(result) // -- lines
}
console.log("Rendering 2 lines\n", renderLines(2)) // - 2
console.log("Rendering 13 lines\n", renderLines(13)) // - 13
console.log("Rendering 4 lines of text and counting lines\n", countTextLines(("a").repeat(process.stdout.columns * 4)))
console.log("Rendering 14 lines of text and counting lines\n", countTextLines(("a").repeat(process.stdout.columns * 14)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment