Create a routine that will generate a text calendar for any year.
Test the calendar by generating a calendar for the year 1969, on a device of the time.
Choose one of the following devices:

 A line printer with a width of 132 characters.
 An IBM 3278 model 4 terminal (80×43 display with accented characters). Target formatting the months of the year to fit nicely across the 80 character width screen. Restrict number of lines in test output to 43.


(Ideally, the program will generate well-formatted calendars for any page width from 20 characters up.)

Kudos (κῦδος) for routines that also transition from Julian to Gregorian calendar.

This task is inspired by Real Programmers Don't Use PASCAL by Ed Post, Datamation, volume 29 number 7, July 1983.

THE REAL PROGRAMMER'S NATURAL HABITAT
"Taped to the wall is a line-printer Snoopy calender for the year 1969."

For further Kudos see task CALENDAR, where all code is to be in UPPERCASE.

For economy of size, do not actually include Snoopy generation in either the code or the output, instead just output a place-holder.



Related task

   Five weekends


----------------------------------------
-- @desc      Class "Calendar"
-- @file      parent script "Calendar"
----------------------------------------
property _months
property _weekdayStr
property _refDateObj
property _year
property _calStr
 
on new (me)
  me._months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
  me._weekdayStr = "Mo Tu We Th Fr Sa Su"
  me._refDateObj = date(1905,1,2)
  return me
end
 
on make (me, year)
  me._year = year
  me._calStr = ""
  -- prefill cal string with spaces
  emptyLine = bytearray(68,32).readRawString(68)&RETURN
  repeat with i = 1 to 38
    put emptyLine after _calStr
  end repeat
  me._write (string(year), 32, 1)
  repeat with i = 1 to 12
    me._writeMonth(i)
  end repeat
  return me._calStr
end
 
on _writeMonth (me, monthNum)
  xOffset = (monthNum-1) mod 3 * 24
  yOffset = (monthNum-1)/3 * 9 + 2
  pre = (20 - me._months[monthNum].length)/2
  me._write(me._months[monthNum], 1+xOffset+pre, 1+yOffset)
  me._write(me._weekdayStr, 1+xOffset, 2+yOffset)
  y = 3
  x = ((date(me._year, monthNum, 1) - me._refDateObj) mod 7)+1
  repeat with i = 1 to 31
    if date(me._year, monthNum, i).month<>monthNum then exit repeat
    dayStr = string(i)
    if i<10 then put " " before dayStr
    me._write(dayStr, x*3-2+xOffset, y+yOffset)
    if x=7 then
      y = y+1
      x = 1
    else
      x = x+1
    end if
  end repeat
end
 
on _write (me, str, x, y)
  put str into char x to x+str.length-1 of line y of _calStr
end