This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TheOddByte's profile picture

[Monitors] Get the right size?

Started by TheOddByte, 21 December 2013 - 07:25 AM
TheOddByte #1
Posted 21 December 2013 - 08:25 AM
Hello, Recently many on the forums have asked how to make a program or such that writes to the terminal and the monitor at the same time, And I decided to make such a program that can run this through modems or whatever to make it as easy to use as possible, But now my question is how do I get the right textscale for it or whatever it needs like when you use 'monitor <monitor> <program>' and it almost sets the perfect size.. How can I accomplish that?

Edit: For those who want to check out the program
Edited on 21 December 2013 - 07:42 AM
Goobster22 #2
Posted 21 December 2013 - 08:46 AM
To my knowledge there is no way to get the "perfect" size automatically. When I work with monitors I have to do a lot of testing with text sizes and cursor positions. If you did want a precise text scale you could do some math with the "monitor.getSize()" and the size of the text.
Lyqyd #3
Posted 21 December 2013 - 02:15 PM
Start at text scale 5 and check the size, then work your way down until you have enough rows/columns.
TheOddByte #4
Posted 21 December 2013 - 03:56 PM
Well what is it that term.redirect does that makes it align right to the screen then? Does it mess with term.setCursorPos or something?
Wojbie #5
Posted 21 December 2013 - 04:13 PM
Afaik it does nothing of sort - term.redirect() just causes all term functions to get called on selected monitor - align to right side is achieved by programs and code itself based of term.getSize() - witch when redirected returns size of monitor.


On side-note you can take a peek at my version of program for any ideas.
Lyqyd #6
Posted 21 December 2013 - 05:08 PM
like when you use 'monitor <monitor> <program>' and it almost sets the perfect size

For reference, the monitor program does no such thing:



function printUsage()
    print( "Usage: monitor <side> <program> <arguments>" )
    return
end

local tArgs = { ... }
if #tArgs < 2 then
    printUsage()
    return
end

local sSide = tArgs[1]
if peripheral.getType( sSide ) ~= "monitor" then
    print( "No monitor on "..sSide.." side" )
    return
end

local sProgram = tArgs[2]
local sPath = shell.resolveProgram( sProgram )
if sPath == nil then
    print( "No such program: "..sProgram )
    return
end

print( "Running "..sProgram.." on "..sSide.." monitor" )

local monitor = peripheral.wrap( sSide )
term.redirect( monitor )

local co = coroutine.create( function()
    shell.run( sProgram, unpack( tArgs, 3 ) )
end )

local function resume( ... )
    local ok, param = coroutine.resume( co, ... )
    if not ok then
        printError( param )
    end
    return param
end

local ok, param = pcall( function()
    local sFilter = resume()
    while coroutine.status( co ) ~= "dead" do
        local tEvent = { os.pullEventRaw() }
        if sFilter == nil or tEvent[1] == sFilter or tEvent[1] == "terminate" then
            sFilter = resume( unpack( tEvent ) )
        end
        if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "mouse_click") then
            if tEvent[1] == "monitor_touch" and tEvent[2] == sSide then
                sFilter = resume( "mouse_click", 1, unpack( tEvent, 3 ) )
            end
        end
    end
end )

term.restore()
if not ok then
    printError( param )
end

Note the lack of .setTextScale.
TheOddByte #7
Posted 21 December 2013 - 05:58 PM
Oh ok, Thanks for the help anyways.. Do you think it would be hard to implent something like monitor.autoScale() to match the monitor size with the terminal size?
awsmazinggenius #8
Posted 21 December 2013 - 06:03 PM
I'm not sure how hard this would be to do Java-side; especially since the only monitor sizes that don't work weird (for me) are .5, 1, 2, 3, 4 and 5 - no in-betweens.
TheOddByte #9
Posted 21 December 2013 - 06:11 PM
The monitor size that is almost identical to the terminal is 5x3 which has the size 50x19 while the terminal has 51x19 which works pretty great when it doesn't go out of the monitor screen :P/>
Well I'll post a suggestion and see if it gets accepted, IMO this could be very useful.
Bomb Bloke #10
Posted 21 December 2013 - 06:36 PM
I think you misunderstood some of what's been said here - although there's no in-built function that'll automatically choose a monitor font size for you based on the terminal row/column count, it's not that tricky to write your own.

It's simply a case of maxing out the font size, then comparing the number of rows/columns on the monitor to that of the terminal. If the terminal has more of either, reduce the font size and check again - repeat until the monitor can finally fit everything the terminal can, or until you've determined the monitor is just too small to work with.

For examples, check the "monsetup()" function the mirror script wojbie linked above, or the "enforceScreenSize()" function in my BBTetris script.
Alice #11
Posted 22 December 2013 - 07:47 PM
Set the scale of the monitor to five, then reduce the scale by an increment of 0.5 until monitor text size is close to screen size.
TheOddByte #12
Posted 23 December 2013 - 09:42 AM
Well I've gone with the way wojbie does it, But I just thought there was a way to completly get identical sizes for the monitor and terminal.
Anyways.. Thanks for all the help guys! :D/>