Scroll note so that current line is at the top

Hi, I am hoping to write a plugin to emulate emacs ctrl+l command: Pressing ctrl+l once scrolls so that the line the cursor is on is in the center. Pressing ctrl+l again scrolls so that the line is at the top and ctrl+l again scrolls so that the line is at the bottom.

Note: putting the line in the center is not an issue - there are other plugins that do this.

I am having trouble with how to scroll a note so that the line the cursor is on is at the top of the users view. One way would be to get the number of lines in the current view then use the recenter function to recenter the line that would put the cursor line at the top. But I can not find how to get the number of lines in the current view. If I can get one command to recenter, one to move to top and one to move to bottom then I can combine them just fine.

Thanks for any help offered!

(I do see the post " Is there any way to make the line where the cursor is located back to the center/top of the screen? " but from what I can see it only takes care of recentering the cursor line, does not move the line to the top)