Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 06 09:57
    jcubic edited #817
  • Aug 06 09:57
    jcubic labeled #817
  • Aug 06 09:57
    jcubic opened #817
  • Aug 05 20:29
    jcubic commented #803
  • Aug 05 20:20
    jcubic labeled #807
  • Aug 05 19:38
    jcubic commented #805
  • Aug 05 19:23
    jcubic labeled #816
  • Aug 03 14:18
    jcubic edited #805
  • Aug 03 14:15
    jcubic milestoned #623
  • Aug 03 14:15
    jcubic commented #623
  • Jul 31 14:46
    jcubic labeled #810
  • Jul 31 14:44
    jcubic labeled #608
  • Jul 30 22:50
    jcubic edited #801
  • Jul 30 22:28
    jcubic edited #801
  • Jul 30 22:20
    jcubic milestoned #769
  • Jul 30 22:19
    jcubic commented #769
  • Jul 30 20:48
    jcubic commented #740
  • Jul 30 20:34
    jcubic edited #801
Jagg3127-alt
@jagg3127-alt
ok'
Jakub T. Jankiewicz
@jcubic
You can delete this code I've said that you don't need typing animation anymore it was added to the library:
  var anim = false;
  function typed(finish_typing) {
      return function(term, message, delay, finish) {
          anim = true;
          var prompt = term.get_prompt();
          var c = 0;
          if (message.length > 0) {
              term.set_prompt('');
              var new_prompt = '';
              var interval = setInterval(function() {
                  var chr = $.terminal.substring(message, c, c+1);
                  new_prompt += chr;
                  term.set_prompt(new_prompt);
                  c++;
                  if (c == length(message)) {
                      clearInterval(interval);
                      // execute in next interval
                      setTimeout(function() {
                          // swap command with prompt
                          finish_typing(term, message, prompt);
                          anim = false
                          finish && finish();
                      }, delay);
                  }
              }, delay);
          }
      };
  }

  function length(string) {
      string = $.terminal.strip(string);
      return $('<span>' + string + '</span>').text().length;
  }

  // those two functions are helpers that animate prompt and animate the message
  var typed_prompt = typed(function(term, message, prompt) {
      term.set_prompt(message + ' ');
  });

  var typed_message = typed(function(term, message, prompt) {
      term.echo(message)
      term.set_prompt(prompt);
  });
I can create PR to fix your code
Jagg3127-alt
@jagg3127-alt
ok
ok i gotta go
talk later
Jakub T. Jankiewicz
@jcubic
Jakub T. Jankiewicz
@jcubic
Just found another bug, I've got few months ago PR that added a feature and still I found bugs in that code
The bug make the animation works wierd, the cursor say in first line
If you want a fix you will again need to use devel version, until I release next version
Jagg3127-alt
@jagg3127-alt
it works yay
thanks so much
Jagg3127-alt
@jagg3127-alt
jcubic is there a way i could instead of typing a super long paragraph inside of the logs function could i store the text in a variable then send it out from there of course in php
Jakub T. Jankiewicz
@jcubic
What you mean send? using email?
Jagg3127-alt
@jagg3127-alt
no like using the send command to type it out
Jakub T. Jankiewicz
@jcubic
I don't follow, can you explan in steps?
There is already send that echo stuff. If you don't want the typing of long text you can check the length of the text if it's longer then 10 characters you can print it, or you can check if there are newlines if yes then echo, i no you can use animation.
I'm not sure if I've understood what you want to do
The user have to only type cred, logs and number
Jagg3127-alt
@jagg3127-alt
ok so storing the text in a variable say like $log1
then use that data to type log 1 on the screen cause i plan on having large paragraphs
Jakub T. Jankiewicz
@jcubic
If think You can send as long command as you want and if you want to include long paragraph you can use code like this:
give me sec I need to search the docs
Jagg3127-alt
@jagg3127-alt
ok
Jakub T. Jankiewicz
@jcubic
You can use code like this in PHP:
<?php

$logs = array(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Praesent id nisl at magna tristique ullamcorper sit amet quis dolor.
Nulla quis leo luctus, elementum massa vitae, ultrices diam.
Quisque eu quam ut elit imperdiet gravida.
Integer mollis condimentum libero, varius pretium justo ullamcorper in.",
"something else"
);

function foo() {
  global $logs;
  return "${logs[0]}";
}

echo foo();
echo "\n";
You basically have array of mutline text, and you return string with interpolation using that array.
In your case when you have logs function you can do
<?php
  function logs($token, $choice = null) {
    $this->valid_token($token);
    global $logs;
    if ($choice == null) {
        return '[[ send "1. \\n2. \\n3. ::logs" ]]';
    } else {
      $choice--;
      if (isset($logs[$choice])) {
        $log = logs[$choice];
        return '[[ send "${$log}::logs::1000" ]]';
      } else {
        throw new Error('Invalid choice');
      }
    }
  }
Jakub T. Jankiewicz
@jcubic
or you can just index from 0 and use choice null as 0.
Jagg3127-alt
@jagg3127-alt
ahhhh ok i understand
Jakub T. Jankiewicz
@jcubic
IF you want to index from 0 and first item in array is your menu than code is even simpler:
<?php
  function logs($token, $choice = 0) {
    $this->valid_token($token);
    global $logs;
    if (isset($logs[$choice])) {
      $log = logs[$choice];
      return '[[ send "${$log}::logs::1000" ]]';
    } else {
      throw new Error('Invalid choice');
    }
  }
but you will need to remove the delay, sorry default choice shoult not have the number at the end otherwise the menu will disappear after 1 second
Jagg3127-alt
@jagg3127-alt
ok
Jakub T. Jankiewicz
@jcubic
sorry not remove index, remove the delay
Jagg3127-alt
@jagg3127-alt
ok
Jakub T. Jankiewicz
@jcubic
<?php
  function logs($token, $choice = 0) {
    $this->valid_token($token);
    global $logs;
    if (isset($logs[$choice])) {
      $log = $logs[$choice];
      if ($choice == 0) {
        return '[[ send "${$log}::logs" ]]';
      } else {
        return '[[ send "${$log}::logs::1000" ]]';
      }
    } else {
      throw new Error('Invalid choice');
    }
  }
this should work and you only need to fill the $logs array
Jagg3127-alt
@jagg3127-alt
ok i think i understand the code too which is great
Jakub T. Jankiewicz
@jcubic
sorry typo logs need to always have $ in front
Updated
Jagg3127-alt
@jagg3127-alt
ok
Jakub T. Jankiewicz
@jcubic
So far this is pretty adanced usage of the library, I have no idea but I assume not not many people even know that they can control the terminal from server.
I'm very pleased how this ended up, the code is quite short in both PHP and JS
Jagg3127-alt
@jagg3127-alt
so im improving evryone elses knowledge of your terminal plugin?
Jakub T. Jankiewicz
@jcubic
yes
Jagg3127-alt
@jagg3127-alt
yay im helpful
Jakub T. Jankiewicz
@jcubic
PS: I think that you have messed up the git repo, you have nested main directory, the project should all be in main directory
Maybe you use clone inside a repo and another in same repo and it create nested directories
Jagg3127-alt
@jagg3127-alt
yeah ik ill fix it in a second im still fixing a couple things with the code itself
Jakub T. Jankiewicz
@jcubic
Will you delete that repo after you've done? Will you publish end result online, for public view?