ttimer | Terminal countdown timer , written in Go | Command Line Interface library

 by   drgrib Go Version: v1.0.12 License: MIT

kandi X-RAY | ttimer Summary

kandi X-RAY | ttimer Summary

ttimer is a Go library typically used in Utilities, Command Line Interface applications. ttimer has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

ttimer is a simple timer that counts down time left in a terminal window. If run on Mac, Windows, or desktop Linux, it will send silent system notifications at 90% and 100% completion. .
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              ttimer has a low active ecosystem.
              It has 66 star(s) with 4 fork(s). There are 2 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 1 open issues and 5 have been closed. On average issues are closed in 135 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of ttimer is v1.0.12

            kandi-Quality Quality

              ttimer has no bugs reported.

            kandi-Security Security

              ttimer has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              ttimer is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              ttimer releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed ttimer and discovered the below as its top functions. This is intended to give you an instant insight into ttimer implemented functionality, and help decide if they suit your requirements.
            • parseTime takes a time string and returns the corresponding time . Duration
            • Args takes a string t and returns the time . Duration and title .
            • Start starts the timer
            • parseClock is a helper function to parse the hexadecimal string of a time .
            • Main entry point .
            • Parse the command line arguments .
            • AfterWallClock returns a channel which fires when the wall clock is reached
            • mustBeNil panics if err is not nil .
            • WithEventHandler sets the event handler to receive events .
            Get all kandi verified functions for this library.

            ttimer Key Features

            No Key Features are available at this moment for ttimer.

            ttimer Examples and Code Snippets

            Installing,macOS
            Godot img1Lines of Code : 1dot img1License : Permissive (MIT)
            copy iconCopy
            brew install drgrib/tap/ttimer  
            Installing,go get
            Godot img2Lines of Code : 1dot img2License : Permissive (MIT)
            copy iconCopy
            go get github.com/drgrib/ttimer  

            Community Discussions

            QUESTION

            How to access MDI Child's component in MainForm in Delphi?
            Asked 2021-May-21 at 09:28

            I make the code by using Delphi.
            When I press the button, it create a new MDI child form.
            So, the program has multiple MDI child form, and I want to access the component(for example, timer) of each child form in the MainForm.
            MainForm is fsMDIForm, and ChildForm is fsMDIChild.

            Here is the code I tried. But it doesn't work because TChildForm and TForm is not compatible.

            ...

            ANSWER

            Answered 2021-May-21 at 09:28

            You need to use a cast like this:

            Source https://stackoverflow.com/questions/67632863

            QUESTION

            How to "refresh" TListBox?
            Asked 2021-May-12 at 18:47

            I'm creating an app which shows bill numbers, like the one you see at Mcdonald's. A POS system send bill numbers to my app and the numbers are showed in a TListBox called "ListBoxPrep". Then, when the POS system sends my app the number of a bill to be removed, my app gets rid of it from "ListBoxPrep" and add it to "ListBoxReady". Every communication between the POS and my app is done via TCP connection and I have no problem with it.

            The problem I'm facing is that I still see the number remain in "ListBoxPrep" even after deleting it by "pItem->Free();". "pItem" is a pointer of TListBoxItem. I want the numbers disappear as soon as my app receives the "delete signal" from the POS and especially without user's interation such as clicking the panel etc. I think of using TTimer, but I have no idea how to make "ListBoxPrep" refresh by itself. Do you have any idea to do that? Any suggestion would be appreciated. I'm using RAD Studio 10.4.

            After my app received the "delete signal" from the POS, I still see the numbers at right side. They are supposed to disappear.

            As soon as I click the "ListBoxPrep", the numbers disappear.

            ...

            ANSWER

            Answered 2021-May-12 at 18:11

            TIdTCPServer is a multi-threaded component. Its OnExecute event is called in the context of a worker thread. As such, it MUST synchronize with the main UI thread when accessing UI controls (that goes for ShowMessage() too, BTW). You can use the RTL's TThread::Synchronize() (synchronous) or TThread::Queue() (asynchronous) method for that.

            Also, you should not be Free()'ing the TListBoxItem objects directly. You have the index of the desired item, you can use ListBoxPrep->Items->Delete() instead.

            If you are using one of the clang-based compilers, try something more like this:

            Source https://stackoverflow.com/questions/67507117

            QUESTION

            Can I safely enable TTimer from a non-UI thread?
            Asked 2021-May-10 at 19:47

            I'm using Delphi XE7 on Windows 10.

            I have been using the following code for a long time, and just read the documentation on SetTimer(). To state it simply, I am setting timers from non-UI threads, but Microsoft's documentation says they should only be set on the UI thread. Extensive tests show my code works fine, but I can't trust my system to behave the same as other systems, or the Microsoft documentation to be 100% accurate. Can anyone verify whether this code is OK or not OK?

            The Delphi code will not deadlock, it pretty much just calls SetTimer() (I am aware there is a race condition setting TTimer.FEnabled).

            The MSDN documentation says:

            hWnd

            Type: HWND

            A handle to the window to be associated with the timer. This window must be owned by the calling thread.

            What I'm trying to accomplish is worker threads doing stuff, and when appropriate, they notify the main thread that elements of the UI must be updated, and the main thread updates the UI. I know how to use TThread.Synchronize(), but deadlocks can happen in certain cases. I can use PostMessage() from my worker threads and handle the message in the UI thread.

            Is there any other way in Delphi to notify and update the UI thread?

            ...

            ANSWER

            Answered 2021-May-07 at 17:01

            The TTimer is being constructed in the main UI thread, when the TForm streams in its DFM resource. The TTimer's constructor creates an internal HWND for the timer to receive WM_TIMER messages with. That HWND is thus owned by the main UI thread.

            TForm.Notify() is setting the timer's Enabled property to true, which will call SetTimer(). Notify() is being called in the context of the worker thread, not the main UI thread. This SHOULD NOT work, as stated in SetTimer()'s documentation. Only the main UI thread should be able to start the timer running, since the main UI thread owns the timer's HWND.

            TTimer.UpdateTimer(), which is called internally by the setters of the timer's Enabled, Interval and OnTimer properties, will raise an EOutOfResources exception if SetTimer() fails. So, calling form1.Notify() in TypeThreadTest.Execute() SHOULD NOT work. The only way SetTimer() would not be called in that situation is if either:

            • Interval is 0
            • Enabled is false
            • OnTimer is unassigned

            Otherwise, your worker thread SHOULD be crashing.

            As you have noted, your worker thread can alternatively use TThread.Synchronize() (or TThread.Queue()), or PostMessage() (or SendMessage()), when it wants to notify the main UI thread to do something. These are viable and preferred solutions. Personally, I would opt for TThread.Queue(), eg:

            Source https://stackoverflow.com/questions/67426727

            QUESTION

            how to move two bitmap-image on a canvas
            Asked 2021-Feb-16 at 21:50

            I am writing an animation program under Delphi 7 consisting of moving two discs on a canvas (I choose a PaintBox) with a bounce effect on the edges.

            it's woks fine if I load the pictures one by one: In this case, when the two disks that arrive from time to time are superimposed, no background rectangle appears with even a rather pleasant transparency effect.

            But if I try to generalize the operation with many more discs by introducing for example a Record.

            The movements are ok BUT in this case, when the discs cross, a background rectangle appears in the upper image which spoils everything!

            I even tried to write the code with an Object with :

            ...

            ANSWER

            Answered 2021-Feb-16 at 08:07

            Your code is almost OK.

            As far as I can see your problem is caused by not completely restoring the background before you draw the bitmaps at their new locations. You need to restore the old rects of all spheres before you draw the new ones. Also you need to collect the complete union of all new and old rects before you update to screen.

            As a matter of taste, I would avoid the global variables and make them fields of the form. If you also make PictureStorage a method of the form, everything works.

            The timer interval of 1 seems a bit of an overkill. I would set it to 1000 div 120 (120 FPS).

            I would set doublebuffered to false, as you are already doing your own doublebuffering. Also I would move the form's OnPaint to the paintbox's OnPaint, but that doesn't seem to work for you.

            Here is the replacement of the OnTimer event which should work (I checked an analogue with Delphi 2006, I don't have Delphi7 installed anymore and I don't know what the n means).

            Source https://stackoverflow.com/questions/66184975

            QUESTION

            Call Timer methods / modify properties from other threads in C++ Builder
            Asked 2021-Feb-02 at 22:36

            I'm trying to achieve the following: to call methods or to modify properties of a TTimer timer which was created in the main thread, from another threads.

            Code looks like the following:

            ...

            ANSWER

            Answered 2021-Feb-02 at 22:36

            Is it possible to call it like that, directly

            It is not safe to do so. Always Synchronize when changing the state of VCL components being used in the main VCL thread from from a thread that is not the main VCL thread.

            You can use the static TThread::Synchronize function from with a lambda function that will be executed in the main VCL thread:

            Source https://stackoverflow.com/questions/66017515

            QUESTION

            Why does freeing a member component in a class destructor cause an EInvalidPointer error when the application is closed?
            Asked 2020-Dec-22 at 21:03

            Here is a class I created to add a TLabel to a TTrackBar. The label shows the value of trackbar when dragged and then fades out. An instance is created at runtime and the parent set to the form. It works fine but gives an error when the application is closed if the trackbar still exists. However, there's no problem if the trackbar is freed at runtime and then the application closed. When debugging that line when the application closes (FLabel.Free;) I see that FLabel and the data in it still exists, but it still gives that error. I'm concerned that if I simply remove that line then there'll be a memory leak when freeing the object at run time. I've tried changing it to if Assigned(FLabel) then FLabel.Free; but with no change. I know it must have something to do with the fact that the label's parent has been set.

            ...

            ANSWER

            Answered 2020-Dec-22 at 21:03

            Most often, an invalid-pointer exception means that you try to free an object twice.

            The problem in this case is that a control frees its children when it is freed. So when the form is freed, it also frees the TLabel. Thus, when your TTrackBarLabel.Destroy is executed, your FLabel is a dangling pointer, and you mustn't do FLabel.Free.

            All Delphi developers know that a component frees its owned components when it is freed. It is a less known fact that a control also frees its children.

            In your case, you can simply remove the FLabel.Free. However, this will cause a memory leak if you never set the FLabel's Parent property.

            To make sure the label is automatically freed when the track bar is, make the track bar the owner of the label:

            Source https://stackoverflow.com/questions/65408959

            QUESTION

            Do you know how to emulate holding down a keystroke for any period of time, then releasing it later?
            Asked 2020-Nov-29 at 14:53

            I'm trying to emulate pushing the keyboard V key down while using BASS library to automate Voice Activation push to talk. I've got the BASS library working, just can't get the keyboard to simulate holding down a Key for any length of time!

            Edit: I am trying to get another application ('TeamSpeak 3') to recognize my Key Press & hold as a hardware based Key Press & Hold rather than a software based Key Press & Hold. To help simulate a Push to Talk via my application. I will openly have the source code for anyone that wants it, but I will not be publishing my application for any reason. It's for my personal use and It's out of curiosity if it would work? I understand that any kind of abuse of this kind of app I take as my own personal responsibility.

            Edit2: I have done extensive research. I figure I'm going to have to either use my old Android handheld or a Raspberry Pi. I have a Raspberry Pi Zero, so I am going to see if I can create it as a hardware keyboard. I'll write a program in Delphi to interface it (I have Delphi 10.4.1 Enterprise and hope it will work with Raspberry Pi's linux version.) I have a vmware Debian and Ubuntu os on my computer that I could pre-compile it with? Anyhow the article is here: https://randomnerdtutorials.com/raspberry-pi-zero-usb-keyboard-hid/

            I'm going to go ahead an allow the answer below, because it basically does what my previous request says. To go further than my request requires a lot of work. I'll give an update if I can get it working properly.

            (Delphi 10.4.1 / Target Windows 32-bit)

            Here's my current source code:

            ...

            ANSWER

            Answered 2020-Nov-29 at 06:35

            I designed a simple example where when the user click the mouse on a TButton, it simulate a keystroke every 250mS until the user release the mouse button.

            The OnMouseButtonDown starts a 250mS timer, the OnMouseButtonUp stop the timer. The OnTimer send the keyboard event. The timer is also stopped when the mouse leave the form.

            The .PAS file:

            Source https://stackoverflow.com/questions/65054069

            QUESTION

            How to Invoke the Delphi function from JavaScript using Cef4Delphi
            Asked 2020-Oct-12 at 17:51

            I am beginner in Delphi. Presently using Delphi Berlin version.

            I am trying to invoke Delphi function/method from JavaScript. For example I want to open a new Delphi form on clicking on html button with additional data attribute.

            HTML CODE

            ...

            ANSWER

            Answered 2020-Oct-11 at 12:48

            You can do that in two ways:

            1. Add a JavaScript function in the "onclick" event of that button. That function would only have to call "console.log()" with "OpenMyNewFormInDelphi" or whatever you want as the text parameter. Then use the TChromium.OnConsoleMessage event and check the "aMessage" parameter. In case aMessage has "OpenMyNewFormInDelphi" then send a Windows message to the main form to show your new form in the main application thread. This solution is the easiest, it's not very elegant but it gets the work done. See the DOMVisitor demo for more details.
            2. You can also register a "JavaScript extension" with CEF4Delphi to execute Delphi code from JavaScript. This is by far the most complicated solution because it involves the creation and registration of a custom class inherited from TCefv8HandlerOwn. That class will receive the calls from your JS code and you can send an IPC message to the main browser process if your application needs to do something in response to that JS call. See the JSExtension and JSRTTIExtension demos for more information.

            The full explanation for the JavaScript extension is a bit long but you can read it here : https://github.com/salvadordf/CEF4Delphi/blob/d44db3bf2a3ead0654ca90178161b09bfbe33602/demos/Delphi_VCL/JavaScript/JSExtension/uJSExtension.pas#L122

            Please remember that all TChromium and GlobalCEFApp events are executed in a CEF thread that it's different than the main application thread. The VCL is not thread safe and you may have problems if you create, destroy or modify Windows controls inside those events. The CEF4Delphi demos are oversimplified and you should always move the VCL code outside the those events. The first solution sends a Windows message to the main form for this reason.

            Source https://stackoverflow.com/questions/64303829

            QUESTION

            Creating an object (with a timer) inside a TidHTTPServer.OnCommandGet fails
            Asked 2020-Sep-14 at 16:25

            Inside a TidHTTPServer.OnCommandGet I create a new object. This Object has a timer that should start immediately but doesnt. The TimerEVent never fires! When I create the object somewhere else it works...

            Some code

            ...

            ANSWER

            Answered 2020-Sep-11 at 18:14

            In your object's constructor, you are creating a TTimer ok, but you are setting its Enabled property to False. So make sure you actually activate the timer once the constructor has exited. Or else change False to True in the constructor.

            That being said, your code still won't work as shown. This is because TIdHTTPServer is a multi-threaded component, its OnCommand... events are fired in the context of worker threads that TIdHTTPServer creates for itself when clients connect to the server. But TTimer is a message-based timer, it creates an internal HWND for itself which is tied to the thread that it is created in, and that thread must have a message loop in order for TTimer to process WM_TIMER messages. The worker thread that you are creating your TTimer in does not have a message loop, so the TTimer will not be able to fire its OnTimer event.

            So, you will have to either:

            1. run your own message loop inside of the OnCommand... event handler after creating your object, and then free the object before the event handler exits. There is no guarantee that the calling thread will continue running once the OnCommand... event handler has exited. Just note that the client will be blocked from sending any further HTTP commands to the server while the timer is running:

            Source https://stackoverflow.com/questions/63851288

            QUESTION

            Sigevent timer can't be restarted nor it executes a callback
            Asked 2020-Jul-24 at 19:18

            I have a t_timer set using a struct sigevent and a struct itimerspec of 6 seconds.

            My program is supposed to refresh this timer if a certain event happens, otherwise, at timer expiration, the callback should be executed and finally the program should stop

            However not only the callback is completely ignored, but I can't restart said timer.

            The following is some prelude code, with the variables used in my class. I tried to shorten and simplify the code as much as possible.

            ...

            ANSWER

            Answered 2020-Jul-24 at 19:18

            I've found something about this. If you use SIGEV_THREAD_ID, the timer will send a signal to the thread id. So you have to install a signal handler in the thread and the function catch_alarm won't be called, just the signal handler, but in the thread.

            If you use SIGEV_THREAD, then the function catch_alarm will be called, but you can't set the thread id as it will be created on your behalf.

            The following code works as you expect:

            Source https://stackoverflow.com/questions/63076106

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install ttimer

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/drgrib/ttimer.git

          • CLI

            gh repo clone drgrib/ttimer

          • sshUrl

            git@github.com:drgrib/ttimer.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Command Line Interface Libraries

            ohmyzsh

            by ohmyzsh

            terminal

            by microsoft

            thefuck

            by nvbn

            fzf

            by junegunn

            hyper

            by vercel

            Try Top Libraries by drgrib

            dotmap

            by drgribPython

            alfred-bear

            by drgribGo

            alfred

            by drgribGo

            maps

            by drgribGo