-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cursor): Fixes cursor save/get position/bookmarking
- Loading branch information
1 parent
1bb6762
commit 7deadea
Showing
5 changed files
with
78 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,7 @@ export default { | |
) | ||
print(``) | ||
print(await commandHelp(props)) | ||
|
||
console.log(props.arguments) | ||
}, | ||
} |
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 @@ | ||
import { cursor, inputKey, print, type Props } from "bluebun" | ||
|
||
export default { | ||
name: "cursor", | ||
description: "Tests cursor movement and bookmarking.", | ||
run: async (props: Props) => { | ||
print(``) | ||
print(`Testing cursor movement and bookmarking.`) | ||
print(``) | ||
|
||
while (true) { | ||
const k = await inputKey() | ||
if (k === "q") break | ||
if (k === "ctrl-c") break | ||
if (k === "esc") break | ||
if (k === "up") cursor.up() | ||
if (k === "down") cursor.down() | ||
if (k === "left") cursor.back() | ||
if (k === "right") cursor.forward() | ||
if (k === "backspace") cursor.backspace() | ||
if (k === "enter") cursor.moveDown() | ||
// if alphabetical, write it | ||
if (k.length === 1 && k.match(/[a-z]/i)) cursor.write(k) | ||
|
||
// if it's a number, go to the bookmark | ||
if (k.length === 1 && k.match(/[0-9]/)) { | ||
// if it's already a bookmark, go to it | ||
const pos = cursor.getBookmark(`bookmark-${k}`) | ||
if (pos) { | ||
cursor.goToPosition(pos.cols, pos.rows) | ||
} else { | ||
// save the position as a bookmark | ||
await cursor.bookmark(`bookmark-${k}`) | ||
} | ||
} | ||
} | ||
}, | ||
} |
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,11 @@ | ||
import { cursor, inputKey, print, type Props } from "bluebun" | ||
|
||
export default { | ||
name: "demo", | ||
description: "Lets you test various features of Bluebun.", | ||
run: async (props: Props) => { | ||
print(``) | ||
print(`Try "bluebun demo cursor".`) | ||
print(``) | ||
}, | ||
} |
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