I’d like to mimic how this paging works:

Notice how the current page will always show two pages on either side? This seems like it would be a lot of conditional code when you factor in the case that you may be on page 4 and there is no gap between 1 and 3 or if you are on page 1 it will show more than two numbers to the right.
Can somebody get me off to the right start?
Here’s sample output from console program with logic you are looking for:
Program.exe 1
1 2 3…100
Program.exe 2
1 2 3 4…100
Program.exe 5
1…3 4 5 6 7…100