From 4c7934102bea39f002f637ebf12863bf99dd99a7 Mon Sep 17 00:00:00 2001 From: Xander Date: Mon, 3 Jul 2023 15:13:48 +0200 Subject: Implemented newline --- kernel/writer.dats | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'kernel/writer.dats') diff --git a/kernel/writer.dats b/kernel/writer.dats index 0d67129..cd6f5d7 100644 --- a/kernel/writer.dats +++ b/kernel/writer.dats @@ -51,14 +51,23 @@ staload WRITER = { end } + fun put_char (c : char, writer: &writer) : void = let val buf = get_buffer() val pos = writer.position in - buf.1->[writer.position] := @{ ascii_character = c, color_code = writer.color_code}; - - if (pos < N - 1) then - writer.position := succ(pos); + if (c = '\n') then + let + val new_pos = (pos / BUFFER_WIDTH + 1) * BUFFER_WIDTH + in + if (new_pos < N) then + writer.position := new_pos + end + else ( + buf.1->[writer.position] := @{ ascii_character = c, color_code = writer.color_code}; + + if (pos < N - 1) then + writer.position := succ(pos)); let prval() = eat_buffer buf in () end end @@ -69,8 +78,5 @@ implement put_string (str : string) : void = let implement string_foreach$fwork (c,env) = put_char(c,env) val _ = string_foreach_env (g1ofg0(str),!p_val) prval() = fpf(pf) -in -end - - +in end -- cgit v1.2.3