Skip to content

Commit

Permalink
fixup! ls: Show keys and values
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrahms committed Feb 28, 2024
1 parent 52463b4 commit b3da673
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/commands/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You should have received a copy of the GNU General Public License along with @p0
import { fetchCommand } from "../drivers/api";
import { authenticate } from "../drivers/auth";
import { guard } from "../drivers/firestore";
import { print2, print1 } from "../drivers/stdio";
import { print2, print1, Ansi } from "../drivers/stdio";
import { max } from "lodash";
import pluralize from "pluralize";
import yargs from "yargs";
Expand Down Expand Up @@ -78,8 +78,8 @@ const ls = async (
isSameValue
? item.key
: maxLength > 30
? `${item.key}\n \u001b[02m${tagPart}\u001b[00m`
: `${item.key.padEnd(maxLength)}\u001b[02m - ${tagPart}\u001b[00m`
? `${item.key}\n ${Ansi.Dim}${tagPart}${Ansi.Reset}`
: `${item.key.padEnd(maxLength)}${Ansi.Dim} - ${tagPart}${Ansi.Reset}`
);
}
} else {
Expand Down
9 changes: 9 additions & 0 deletions src/drivers/stdio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ This file is part of @p0security/p0cli
You should have received a copy of the GNU General Public License along with @p0security/p0cli. If not, see <https://www.gnu.org/licenses/>.
**/

/** Functions to handle stdio
*
* These are essentially wrappers around console.foo, but allow for
* - Better testing
* - Later redirection / duplication
*/
import { mapValues } from "lodash";

/** Used to output machine-readable text to stdout
*
Expand All @@ -33,3 +35,10 @@ export function print2(message: any) {
// eslint-disable-next-line no-console
console.error(message);
}

const AnsiCodes = {
Reset: "00",
Dim: "02",
} as const;

export const Ansi = mapValues(AnsiCodes, (v) => `\u001b[${v}m`);

0 comments on commit b3da673

Please sign in to comment.