[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  ANSI to styles conversion
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

ANSI to styles conversion

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by FxF   (5 posts)  [Biography] bio
Date Tue 19 May 2009 08:21 AM (UTC)
Message
Hi,
I'm trying to move mud minimap to separate miniwindow. This is for Nodeka mud and the problem is that the start and the end of map cannot be triggered by some text pattern. However, I have found out that Nodeka sends some nonprintable chars at the beggining and end of the map.

I have created this plugin so far:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, May 18, 2009, 8:38 PM -->
<!-- MuClient version 4.40 -->

<!-- Plugin "nodeka_windows" generated by Plugin Wizard -->

<muclient>
<plugin
   name="nodeka_windows"
   id="a8260a455abf46e3895aa9e2"
   language="Lua"
   date_written="2009-05-18 20:38:25"
   requires="4.40"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Script  -->


<script>
<![CDATA[
map_start_reg = rex.new("\033\[2m\033\[4m\033\[2m")
map_end_reg   = rex.new("\033\[4m\033\[2m\033\[4m")
map_line      = false
map           = ""

function OnPluginPacketReceived(packet)
  local map_start_ind, map_end_ind
  start, stop, mtable = map_start_reg:match(packet)
  if start then
    Note("Map start")
    map_line      = true
    map_start_ind = start
  end
  start, stop, mtable = map_end_reg:match(packet)
  if start then
    Note("Map end")
    map_line      = false
    map_end_ind   = stop
  end
  if not map_line and not map_start_ind and not map_end_ind then  -- we are outside of map packet
    packet_left = packet
  elseif map_line and not map_start_ind and not map_end_ind then  -- we are inside of map packet
    map = map .. packet
    packet_left = ""
  elseif not map_line and map_start_ind and map_end_ind then      -- whole map inside of 1 packet
    map = string.sub(packet, map_start_ind, map_end_ind)
    packet_left = string.sub(packet, 1, map_start_ind)..string.sub(packet, map_end_ind)
    UpdateMap()
  elseif map_line and map_start_ind and not map_end_ind then      -- start of the map
    map = string.sub(packet, map_start_ind)
    packet_left = string.sub(packet, 1, map_start_ind)
  elseif not map_line and not map_start_ind and map_end_ind then  -- end of the map
    map = map .. string.sub(packet, 1, map_end_ind)
    packet_left = string.sub(packet, map_end_ind)
    UpdateMap()
  else                                                    -- corner cases - more maps in one packet etc.
    packet_left = packet
  end
  return packet_left
end

function UpdateMap()
  AnsiNote(map)
  map=""
end


]]>
</script>


</muclient>


map_start_reg and map_end_reg are the regular expressions that mark the beginning and the end of map. As you can see, they are nonprintable chars. AFAIK I can match nonprintable chars only by regexp and only from raw packets, which complicates the situation. This plugin works, but I would like to change the UpdateMap function to draw the map into the miniwindow. The problem is that map string contains raw text with ANSI escapes. Is there any good way to write this text with colors into miniwindow? I can create my own function in Lua to convert the ANSI into the styled text with the help of regexp, but it might be both quite complex and the result might slow down the things as well.
[Go to top] top

Posted by FxF   (5 posts)  [Biography] bio
Date Reply #1 on Tue 19 May 2009 08:25 AM (UTC)
Message
Sorry for not escaping the patterns for the forums.
map_start_reg and map_end_reg should have two \ everywhere, otherwise the plugin won't work. I'm using the MUSHClient from WINE and working with clipboard is tricky sometimes :)

BTW MUSHClient under WINE has some problems but I guess it doesn't belong to this thread.
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


1,989 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]