-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
159 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import writeHistoryCommand from "../writeToTerminal/writeHistoryCommand" | ||
import writeHistoryCommand from "../writeToTerminal/writeHistoryCommand.js" | ||
|
||
export default function handleArrowDown(term, historyIndex, commandHistory, prefixLength) { | ||
export default function handleArrowDown(term, historyIndex, commandHistory) { | ||
if (historyIndex > -1) { | ||
historyIndex-- | ||
const command = historyIndex >= 0 ? commandHistory[historyIndex] : "" | ||
writeHistoryCommand(term, command, prefixLength) | ||
writeHistoryCommand(term, command) | ||
} | ||
return historyIndex | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import writeHistoryCommand from "../writeToTerminal/writeHistoryCommand" | ||
import writeHistoryCommand from "../writeToTerminal/writeHistoryCommand.js" | ||
|
||
export default function handleArrowUp(term, historyIndex, commandHistory, prefixLength) { | ||
export default function handleArrowUp(term, historyIndex, commandHistory) { | ||
if (historyIndex < commandHistory.length - 1) { | ||
historyIndex++ | ||
const command = commandHistory[historyIndex] | ||
writeHistoryCommand(term, command, prefixLength) | ||
writeHistoryCommand(term, command) | ||
} | ||
return historyIndex | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
export default function writeHistoryCommand(term, command, prefixLength) { | ||
import { getCommandLinePrefix } from "../../config/commandLineConfig.js" | ||
import { writeColoredText } from "./writeColoredText.js" | ||
|
||
export default function writeHistoryCommand(term, command) { | ||
term.write("\x1b[2K\r") | ||
term.write(" ".repeat(prefixLength)) | ||
term.write("\r") | ||
term.write(" ".repeat(prefixLength) + command) | ||
const prefix = getCommandLinePrefix() | ||
prefix.forEach((part) => { | ||
writeColoredText(term, part.text, part.color, true) | ||
}) | ||
term.write(command) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export default function writeTable(term, data) { | ||
if (!Array.isArray(data) || data.length === 0) { | ||
term.writeln("No data to display") | ||
return | ||
} | ||
|
||
const headers = data[0] | ||
const rows = data.slice(1) | ||
|
||
// Calculate column widths | ||
const columnWidths = headers.map((header, index) => { | ||
const maxWidth = Math.max(header.length, ...rows.map((row) => String(row[index]).length)) | ||
return maxWidth + 2 // Add padding | ||
}) | ||
|
||
// Print headers | ||
let headerRow = "│" | ||
headers.forEach((header, index) => { | ||
headerRow += ` ${header.padEnd(columnWidths[index])}│` | ||
}) | ||
const separator = "─".repeat(headerRow.length) | ||
|
||
term.writeln(separator) | ||
term.writeln(headerRow) | ||
term.writeln(separator) | ||
|
||
// Print rows | ||
rows.forEach((row) => { | ||
let rowString = "│" | ||
row.forEach((cell, index) => { | ||
rowString += ` ${String(cell).padEnd(columnWidths[index])}│` | ||
}) | ||
term.writeln(rowString) | ||
}) | ||
|
||
term.writeln(separator) | ||
term.write("\r\n") | ||
} |