dc, 98 bytes
256?dse1+d[q]st1=t^124*23562+dsaP2sk[[lkd256r^32*la+dsaPd1+skle>y]srle1<r]dsyx[45Ple1-dse0!>q]dsqx
Try it online!
Explanation
This takes due advantage of dc's P
command, which utilizes conversion to base 256
on most systems. Therefore, for any input n
, the program first raises 256
to the n + 1
th power, multiplies the result by 124
(ASCII character |
), and then adds 256*92+10=23562
to the product (where 92
is equivalent to the character \
and 10
is the decimal value of the new-line (\n
)). This results in a decimal number that when converted to base 256
with P
results in the output |\\n
where \n
is the literal new-line character. A duplicate of this decimal number is also stored on top of register a
.
Then, a "macro-loop" is invoked, as long as n > 1
, in which a counter is incremented until n
, beginning from 2
, and, as the 3rd through n
th base 256
digits are unset, 256
is raised to each of those increments, a result which is then multiplied by 32
(the ASCII single space character). Then the value on top of register a
is incremented by the resulting product, thus, on each iteration, setting each one of the unset base 256
digits in the between the |
and the \
characters to a single space.
Finally, after all n-1
lines have been output, another "macro-loop" is invoked in which all the n+1
dashes are output through the feeding of 45
to P
on each iteration.
Note: The [q]st1=t
segment makes sure that nothing is output for the input 0
by checking if the incremented input is equal to one, and if it is, simply executes the macro [q]
which exits the program.
0
can have any unexpected output since it is an edge case (especially since you requested that the number of dashes must be one more than the input number) \$\endgroup\$