More

Application Kata “More”

Write a console application to display the content of a text file in a pagewise manner. It should be called like this:

C:> more 

Upon start the first page is shown (page length = 20 lines) and the application waits for the user to press a key to show the next page. Pressing [Esc] exits the application. Example:

C:> more kublaakhan.txt
In Xanadu did Kubla Khan
A stately pleasure-dome decree:
…
As if this earth in fast thick pants were breathing,
A mighty fountain momently was forced:
--- Press any key to show next page. Exit by pressing [Esc] ---

After pressing for example the space bar this would be displayed:

Amid whose swift half-intermitted burst
Huge fragments vaulted like rebounding hail,
…
A damsel with a dulcimer
In a vision once I saw:
--- Press any key to show next page. Exit by pressing [Esc] ---

etc.

Variation #1

Allow for a user defined page length, e.g.

C:> more coleridge.txt 10

Variation #2

Show the current page number and the total number of pages at the top of each page, e.g.

C:> more kublaakhan.txt
--- Page 1 of 3 ---
In Xanadu did Kubla Khan
A stately pleasure-dome decree:
…