question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can ink be used as a "full" screen application?

See original GitHub issue

Hey; I love the concept of this library. Just wondering if it’s possible to make a “full” screen application using ink? By that I mean, something like htop which takes over the full screen, and when you quit - it leaves your original terminal completely in tact.

This is something that can be done with python’s curses library, or when using blesses:

var blessed = require('blessed');

// Create a screen object.
var screen = blessed.screen({
  smartCSR: true
});

var box = blessed.box({
  top: 'center',
  left: 'center',
  width: '50%',
  height: '50%',
  content: 'Hello {bold}world{/bold}!',
  tags: true,
  border: {
    type: 'line'
  },
  style: {
    fg: 'white',
    bg: 'magenta',
    border: {
      fg: '#f0f0f0'
    },
    hover: {
      bg: 'green'
    }
  }
});

screen.append(box);

screen.key(['escape', 'q', 'C-c'], function(ch, key) {
  return process.exit(0);
});

screen.render()

Which opens the “full” screen application, and leaves the original terminal intact after quitting it. Any pointers/direction would be appreciated 👍

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:11
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

30reactions
AlanFostercommented, Mar 19, 2020

@taras I learnt more about curses/ncurses and terminfo, via man terminfo.

I found out you can use ansi escape codes to swap to an alternate screen buffer for ‘full screen’ applications, and once you’re done you can toggle back to the main buffer:

const enterAltScreenCommand = '\x1b[?1049h';
const leaveAltScreenCommand = '\x1b[?1049l';
process.stdout.write(enterAltScreenCommand);
process.on('exit', () => {
    process.stdout.write(leaveAltScreenCommand);
});

Therefore as a full example:

const React = require("react");
const { render, Color, useApp, useInput } = require("ink");

const Counter = () => {
  const [counter, setCounter] = React.useState(0);
  const { exit } = useApp();

  React.useEffect(() => {
    const timer = setInterval(() => {
      setCounter(prevCounter => prevCounter + 1);
    }, 100);

    return () => {
      clearInterval(timer);
    };
  });

  useInput((input, key) => {
    if (input === "q" || key.escape) {
      exit();
    }
  });

  return <Color green>{counter} tests passed</Color>;
};

const enterAltScreenCommand = "\x1b[?1049h";
const leaveAltScreenCommand = "\x1b[?1049l";
process.stdout.write(enterAltScreenCommand);
process.on("exit", () => {
  process.stdout.write(leaveAltScreenCommand);
});

render(<Counter />);

Working example that doesn’t conflict with the existing buffer:

alt-screen-buffer

That seems to be what I was after - I’m not sure if that’s something that should be baked into ink or not.

26reactions
prozacgodcommented, Jan 22, 2021

Just wanted to add a bit in here, kinda an old thread but…

This is my fullscreen (typescript) component, it tracks the process.stdout resize event and updates a box on resize, works nicely

const FullScreen: React.FC = (props) => {
	const [size, setSize] = useState({
		columns: process.stdout.columns,
		rows: process.stdout.rows,
	});

	useEffect(() => {
		function onResize() {
			setSize({
				columns: process.stdout.columns,
				rows: process.stdout.rows,
			});
		}

		process.stdout.on("resize", onResize);
		process.stdout.write("\x1b[?1049h");
		return () => {
			process.stdout.off("resize", onResize);
			process.stdout.write("\x1b[?1049l");
		};
	}, []);

	return (
		<Box width={size.columns} height={size.rows}>
			{props.children}
		</Box>
	);
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ink view in OneNote full screen - Reddit
New full screen ink view is available in Version 2211 (German) DEMO: ... The most powerful update from my use case view.
Read more >
Microsoft's new Ink Workspace is less than you'd think from the ...
All three of these new Microsoft pen apps also aren't really full applications. They come up full screen, and not only can't be...
Read more >
How do I get Snip and Sketch to go fullscreen like ...
I want to know if there is a way to make snip and sketch go full screen like screensketch used to, or if...
Read more >
Reference handbook for using Ink v3.2.0 components (w
The useApp() hook supplies an exit() function which can be used to do this. Example 3 - full screen app #. This large...
Read more >
Using Windows 10 | Microsoft Press Store
Using the Windows Ink workspace ... Whiteboard provides a canvas on which you and teammates can share text, drawings, graphics, and imported PDFs ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found