A digital clock in a thread

My code goes here - http://pastebin.com/yCkqiR4M

I'm new to threading and also new to animations.

I'm trying to run a thread that prints out the time in (H:M:S) format.

Can you look at it and say something about it?
I want the clock to run on it's own part of the screen without
interfering with my "what's your name?" thing.

When I run the code this is what happens (and let's think, for now I
type my name as "lol")

Current time - 12:27:31
What's your name?
Current time - 12:27:39ol #"ol" when i typed "lol"
lol is a nice name
Current time - 12:28:55

And yes, I'm new to "\r" carriage return too.

I'm not sure, but perhaps curses would help you to put things at exact
places on the screen.

Abinoam Jr.

···

On Sun, Dec 7, 2014 at 10:44 AM, Cynic limbu <cyniclimbu@gmail.com> wrote:

My code goes here - Threading a clock in Ruby. - Pastebin.com

I'm new to threading and also new to animations.

I'm trying to run a thread that prints out the time in (H:M:S) format.

Can you look at it and say something about it?
I want the clock to run on it's own part of the screen without
interfering with my "what's your name?" thing.

When I run the code this is what happens (and let's think, for now I
type my name as "lol")

Current time - 12:27:31
What's your name?
Current time - 12:27:39ol #"ol" when i typed "lol"
lol is a nice name
Current time - 12:28:55

And yes, I'm new to "\r" carriage return too.

Curses would be a good approach, but you haven't really defined what you
want your interaction to be like?

It's not a good approach, but another way would be to just wrap the stream
calls in a mutex.

Something like this: http://pastebin.com/58aFQBPx

I didn't actually test that, but if you are just trying to learn threading,
it should help out.

···

On Sun Dec 07 2014 at 5:12:05 PM Abinoam Jr. <abinoam@gmail.com> wrote:

I'm not sure, but perhaps curses would help you to put things at exact
places on the screen.

GitHub - ruby/curses: Ruby binding for curses, ncurses, and PDCurses. Formerly part of the ruby standard library.

Abinoam Jr.

On Sun, Dec 7, 2014 at 10:44 AM, Cynic limbu <cyniclimbu@gmail.com> wrote:
> My code goes here - Threading a clock in Ruby. - Pastebin.com
>
> I'm new to threading and also new to animations.
>
> I'm trying to run a thread that prints out the time in (H:M:S) format.
>
> Can you look at it and say something about it?
> I want the clock to run on it's own part of the screen without
> interfering with my "what's your name?" thing.
>
> When I run the code this is what happens (and let's think, for now I
> type my name as "lol")
>
> Current time - 12:27:31
> What's your name?
> Current time - 12:27:39ol #"ol" when i typed "lol"
> lol is a nice name
> Current time - 12:28:55
>
> And yes, I'm new to "\r" carriage return too.

Thanks, will check it out.

···

On Mon, Dec 8, 2014 at 9:11 AM, Abinoam Jr. <abinoam@gmail.com> wrote:

I'm not sure, but perhaps curses would help you to put things at exact
places on the screen.

GitHub - ruby/curses: Ruby binding for curses, ncurses, and PDCurses. Formerly part of the ruby standard library.

Abinoam Jr.

On Sun, Dec 7, 2014 at 10:44 AM, Cynic limbu <cyniclimbu@gmail.com> wrote:
> My code goes here - Threading a clock in Ruby. - Pastebin.com
>
> I'm new to threading and also new to animations.
>
> I'm trying to run a thread that prints out the time in (H:M:S) format.
>
> Can you look at it and say something about it?
> I want the clock to run on it's own part of the screen without
> interfering with my "what's your name?" thing.
>
> When I run the code this is what happens (and let's think, for now I
> type my name as "lol")
>
> Current time - 12:27:31
> What's your name?
> Current time - 12:27:39ol #"ol" when i typed "lol"
> lol is a nice name
> Current time - 12:28:55
>
> And yes, I'm new to "\r" carriage return too.

I want the clock to run on the first line of the shell
And when I'm typing my name in when it's asking, I want the clock to just
stay where it is and not clone itself on the second line.

The output of your code is same to mine.
When it prints out "What's your name?"
The current time clones itself and prints its value after "whats your
name?" has been asked. Which is what I'm trying to avoid.

···

On Mon, Dec 8, 2014 at 1:09 PM, Raj Sahae <rajsahae@gmail.com> wrote:

Curses would be a good approach, but you haven't really defined what you
want your interaction to be like?

It's not a good approach, but another way would be to just wrap the stream
calls in a mutex.

Something like this: http://pastebin.com/58aFQBPx

I didn't actually test that, but if you are just trying to learn
threading, it should help out.

On Sun Dec 07 2014 at 5:12:05 PM Abinoam Jr. <abinoam@gmail.com> wrote:

I'm not sure, but perhaps curses would help you to put things at exact
places on the screen.

https://github.com/ruby/curses

Abinoam Jr.

On Sun, Dec 7, 2014 at 10:44 AM, Cynic limbu <cyniclimbu@gmail.com> >> wrote:
> My code goes here - Threading a clock in Ruby. - Pastebin.com
>
> I'm new to threading and also new to animations.
>
> I'm trying to run a thread that prints out the time in (H:M:S) format.
>
> Can you look at it and say something about it?
> I want the clock to run on it's own part of the screen without
> interfering with my "what's your name?" thing.
>
> When I run the code this is what happens (and let's think, for now I
> type my name as "lol")
>
> Current time - 12:27:31
> What's your name?
> Current time - 12:27:39ol #"ol" when i typed "lol"
> lol is a nice name
> Current time - 12:28:55
>
> And yes, I'm new to "\r" carriage return too.