# encoding: ascii
# api: powershell
# title: Pause-Script &amp; Out-More
# description: Two functions, one that emulates the pause functionality from cmd.exe, and one that gives similar functionality to more.com.  Out-More is especially useful if you’re doing something like “gc somefile.txt | Out-More” because it starts outputting text to the screen immediately instead of waiting for the entire file to be read, which is what happens if you do “gc somefile.txt | more”.  Out-More can also be used for other objects besides.
# version: 0.1
# type: script
# license: CC0
# function: Pause-Script
# x-poshcode-id: 613
# x-archived: 2011-01-01T11:41:44
#
#
# Pause-Script
#
# Pauses execution until a key is pressed.

function Pause-Script {
  param([string]$message = 'Press any key to continue...')
  Write-Host -NoNewLine $message
  $null = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown")
  Write-Host ""
}


# Out-More
#
# Displays one window's worth of data at a time.
#
# Args:
#   $window_size: The number of lines to display
#
# Returns:
#   Each object in the input pipeline.

function Out-More {
  param ([int]$window_size = ($Host.UI.RawUI.WindowSize.Height - 1))
  $i = 0

  foreach ($line in $input) {
    Write-Output $line
    $i += 1

    if ($i -eq $window_size) {
      Pause-Script
      $i = 0
    }
  }
}
